‪TYPO3CMS  11.5
StringFragmentSplitterTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪StringFragmentSplitterTest extends UnitTestCase
26 {
27  public static function ‪stringIsSplitDataProvider(): \Generator
28  {
29  $expressionPattern = new ‪StringFragmentPattern(‪StringFragmentSplitter::TYPE_EXPRESSION, '\\$[^$]+\\$');
31 
32  yield 'Hello World! (unmatched with `raw` only)' => [
33  'Hello World!',
34  [$expressionPattern, $otherPattern],
35  0,
36  [
37  ‪StringFragment::raw('Hello World!'),
38  ],
39  ];
40  yield 'Hello World! (unmatched as null)' => [
41  'Hello World!',
42  [$expressionPattern, $otherPattern],
44  null,
45  ];
46  yield 'Hello$expr$World!' => [
47  'Hello$expr$World!',
48  [$expressionPattern, $otherPattern],
49  0,
50  [
51  ‪StringFragment::raw('Hello'),
53  ‪StringFragment::raw('World!'),
54  ],
55  ];
56  yield 'Hello $expr$ World!' => [
57  'Hello $expr$ World!',
58  [$expressionPattern, $otherPattern],
59  0,
60  [
61  ‪StringFragment::raw('Hello '),
63  ‪StringFragment::raw(' World!'),
64  ],
65  ];
66  yield '$expr$ combined with !other!' => [
67  '$expr$ combined with !other!',
68  [$expressionPattern, $otherPattern],
69  0,
70  [
72  ‪StringFragment::raw(' combined with '),
74  ],
75  ];
76  }
77 
85  public function ‪stringIsSplit(string $value, array $patterns, int $flags, ?array $expectations): void
86  {
87  $splitter = new ‪StringFragmentSplitter(...$patterns);
88  $collection = $splitter->split($value, $flags);
89 
90  if ($expectations === null) {
91  self::assertNull($collection);
92  } else {
93  self::assertEquals($expectations, $collection->getFragments());
94  }
95  }
96 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\String
Definition: StringFragmentCollectionTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentSplitterTest\stringIsSplitDataProvider
‪static stringIsSplitDataProvider()
Definition: StringFragmentSplitterTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentSplitterTest
Definition: StringFragmentSplitterTest.php:26
‪TYPO3\CMS\Core\Utility\String\StringFragment\expression
‪static expression(string $value)
Definition: StringFragment.php:35
‪TYPO3\CMS\Core\Tests\Unit\Utility\String\StringFragmentSplitterTest\stringIsSplit
‪stringIsSplit(string $value, array $patterns, int $flags, ?array $expectations)
Definition: StringFragmentSplitterTest.php:85
‪TYPO3\CMS\Core\Utility\String\StringFragment\raw
‪static raw(string $value)
Definition: StringFragment.php:30
‪TYPO3\CMS\Core\Utility\String\StringFragmentSplitter
Definition: StringFragmentSplitter.php:27
‪TYPO3\CMS\Core\Utility\String\StringFragmentPattern
Definition: StringFragmentPattern.php:24
‪TYPO3\CMS\Core\Utility\String\StringFragmentSplitter\TYPE_EXPRESSION
‪const TYPE_EXPRESSION
Definition: StringFragmentSplitter.php:36
‪TYPO3\CMS\Core\Utility\String\StringFragment
Definition: StringFragment.php:24
‪TYPO3\CMS\Core\Utility\String\StringFragmentSplitter\FLAG_UNMATCHED_AS_NULL
‪const FLAG_UNMATCHED_AS_NULL
Definition: StringFragmentSplitter.php:42