‪TYPO3CMS  11.5
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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪StringFragmentCollectionTest extends UnitTestCase
25 {
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 
71  public function ‪differencesAreResolved(array $first, array $second, array $expectations): void
72  {
73  $firstCollection = new ‪StringFragmentCollection(...$first);
74  $secondCollection = new ‪StringFragmentCollection(...$second);
75  $collection = $firstCollection->diff($secondCollection);
76  self::assertEquals($expectations, $collection->getFragments());
77  }
78 
79  public static function ‪intersectionsAreResolvedDataProvider(): \Generator
80  {
81  $a = ‪StringFragment::raw('a');
82  $b = ‪StringFragment::raw('b');
83  $c = ‪StringFragment::raw('c');
84 
85  yield [
86  [$a, $b, $c],
87  [],
88  [],
89  ];
90  yield [
91  [$a, $b, $c],
92  [$a, $b, $c],
93  [$a, $b, $c],
94  ];
95  yield [
96  [$a, $b, $c],
97  [$a, $c],
98  [$a, $c],
99  ];
100  }
101 
110  public function ‪intersectionsAreResolved(array $first, array $second, array $expectations): void
111  {
112  $firstCollection = new ‪StringFragmentCollection(...$first);
113  $secondCollection = new ‪StringFragmentCollection(...$second);
114  $collection = $firstCollection->intersect($secondCollection);
115  self::assertEquals($expectations, $collection->getFragments());
116  }
117 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\differencesAreResolved
‪differencesAreResolved(array $first, array $second, array $expectations)
Definition: StringFragmentCollectionTest.php:71
‪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:79
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentCollectionTest\intersectionsAreResolved
‪intersectionsAreResolved(array $first, array $second, array $expectations)
Definition: StringFragmentCollectionTest.php:110
‪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:25
‪TYPO3\CMS\Core\Utility\String\StringFragment\raw
‪static raw(string $value)
Definition: StringFragment.php:30
‪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