‪TYPO3CMS  ‪main
StringFragmentCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪StringFragmentCollectionTest extends UnitTestCase
27 {
28  #[Test]
29  public function ‪collectionReflectsFragments(): void
30  {
31  $a = ‪StringFragment::raw('aa');
32  $b = ‪StringFragment::raw('bb');
33  $collection = new ‪StringFragmentCollection($a, $b);
34  self::assertSame(2, count($collection));
35  self::assertSame([$a, $b], $collection->getFragments());
36  self::assertSame(4, $collection->getLength());
37  self::assertSame('aabb', (string)$collection);
38  }
39 
40  public static function ‪differencesAreResolvedDataProvider(): \Generator
41  {
42  $a = ‪StringFragment::raw('a');
43  $b = ‪StringFragment::raw('b');
44  $c = ‪StringFragment::raw('c');
45 
46  yield [
47  [$a, $b, $c],
48  [],
49  [$a, $b, $c],
50  ];
51  yield [
52  [$a, $b, $c],
53  [$a, $b, $c],
54  [],
55  ];
56  yield [
57  [$a, $b, $c],
58  [$a],
59  [$b, $c],
60  ];
61  }
62 
68  #[DataProvider('differencesAreResolvedDataProvider')]
69  #[Test]
70  public function ‪differencesAreResolved(array $first, array $second, array $expectations): void
71  {
72  $firstCollection = new ‪StringFragmentCollection(...$first);
73  $secondCollection = new ‪StringFragmentCollection(...$second);
74  $collection = $firstCollection->diff($secondCollection);
75  self::assertEquals($expectations, $collection->getFragments());
76  }
77 
78  public static function ‪intersectionsAreResolvedDataProvider(): \Generator
79  {
80  $a = ‪StringFragment::raw('a');
81  $b = ‪StringFragment::raw('b');
82  $c = ‪StringFragment::raw('c');
83 
84  yield [
85  [$a, $b, $c],
86  [],
87  [],
88  ];
89  yield [
90  [$a, $b, $c],
91  [$a, $b, $c],
92  [$a, $b, $c],
93  ];
94  yield [
95  [$a, $b, $c],
96  [$a, $c],
97  [$a, $c],
98  ];
99  }
100 
106  #[DataProvider('intersectionsAreResolvedDataProvider')]
107  #[Test]
108  public function ‪intersectionsAreResolved(array $first, array $second, array $expectations): void
109  {
110  $firstCollection = new ‪StringFragmentCollection(...$first);
111  $secondCollection = new ‪StringFragmentCollection(...$second);
112  $collection = $firstCollection->intersect($secondCollection);
113  self::assertEquals($expectations, $collection->getFragments());
114  }
115 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\differencesAreResolved
‪differencesAreResolved(array $first, array $second, array $expectations)
Definition: StringFragmentCollectionTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Utility\String
Definition: StringFragmentCollectionTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\intersectionsAreResolvedDataProvider
‪static intersectionsAreResolvedDataProvider()
Definition: StringFragmentCollectionTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\intersectionsAreResolved
‪intersectionsAreResolved(array $first, array $second, array $expectations)
Definition: StringFragmentCollectionTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\differencesAreResolvedDataProvider
‪static differencesAreResolvedDataProvider()
Definition: StringFragmentCollectionTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest
Definition: StringFragmentCollectionTest.php:27
‪TYPO3\CMS\Core\Utility\String\StringFragment\raw
‪static raw(string $value)
Definition: StringFragment.php:28
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\collectionReflectsFragments
‪collectionReflectsFragments()
Definition: StringFragmentCollectionTest.php:29
‪TYPO3\CMS\Core\Utility\String\StringFragment
Definition: StringFragment.php:24
‪TYPO3\CMS\Core\Utility\String\StringFragmentCollection
Definition: StringFragmentCollection.php:24