‪TYPO3CMS  11.5
PermutationUtilityTest.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 
27 class ‪PermutationUtilityTest extends UnitTestCase
28 {
29  public function ‪meltStringItemsDataProvider(): array
30  {
31  return [
32  'string items' => [
33  [
34  ['a', 'b'],
35  ['c', 'd'],
36  ['e', 'f'],
37  ],
38  ['ace', 'acf', 'ade', 'adf', 'bce', 'bcf', 'bde', 'bdf'],
39  ],
40  'string & empty value items' => [
41  [
42  ['a', ''],
43  ['b', ''],
44  ['c', ''],
45  ],
46  ['abc', 'ab', 'ac', 'a', 'bc', 'b', 'c', ''],
47  ],
48  'object::__toString() items' => [
49  [
50  [new ‪StringValue('a'), new ‪StringValue('b')],
51  [new ‪StringValue('c'), new ‪StringValue('d')],
52  [new ‪StringValue('e'), new ‪StringValue('f')],
53  ],
54  ['ace', 'acf', 'ade', 'adf', 'bce', 'bcf', 'bde', 'bdf'],
55  ],
56  'string & object::__toString() items' => [
57  [
58  ['a', new ‪StringValue('b')],
59  ['c', new ‪StringValue('d')],
60  ['e', new ‪StringValue('f')],
61  ],
62  ['ace', 'acf', 'ade', 'adf', 'bce', 'bcf', 'bde', 'bdf'],
63  ],
64  'string items with invalid object' => [
65  [
66  ['a', 'b'],
67  ['c', 'd'],
68  ['e', 'f', new \stdClass()],
69  ],
70  1578164102,
71  ],
72  'string items with invalid integer' => [
73  [
74  ['a', 'b'],
75  ['c', 'd'],
76  ['e', 'f', 123],
77  ],
78  1578164102,
79  ],
80  'string items with invalid boolean' => [
81  [
82  ['a', 'b'],
83  ['c', 'd'],
84  ['e', 'f', true],
85  ],
86  1578164102,
87  ],
88  'string items with invalid array' => [
89  [
90  ['a', 'b'],
91  ['c', 'd'],
92  ['e', 'f', []],
93  ],
94  1578164102,
95  ],
96  'string items with invalid invocation' => [
97  [
98  'a', 'b',
99  ],
100  1578164101,
101  ],
102  ];
103  }
104 
112  public function ‪meltStringItemsIsExecuted(array $payload, $expectation): void
113  {
114  if (is_int($expectation)) {
115  $this->expectException(\LogicException::class);
116  $this->expectExceptionCode($expectation);
117  }
118  self::assertSame($expectation, ‪PermutationUtility::meltStringItems($payload));
119  }
120 
121  public function ‪meltArrayItemsDataProvider(): array
122  {
123  $aStringValue = new ‪StringValue('a');
124  $bStringValue = new ‪StringValue('b');
125  $cStringValue = new ‪StringValue('c');
126  $dStringValue = new ‪StringValue('d');
127 
128  return [
129  'string items' => [
130  [
131  ['a', 'b'],
132  ['c', 'd'],
133  ['e', 'f'],
134  ],
135  [
136  ['a', 'c', 'e'], ['a', 'c', 'f'], ['a', 'd', 'e'], ['a', 'd', 'f'],
137  ['b', 'c', 'e'], ['b', 'c', 'f'], ['b', 'd', 'e'], ['b', 'd', 'f'],
138  ],
139  ],
140  'object::__toString() items' => [
141  [
142  [$aStringValue, $bStringValue],
143  [$cStringValue, $dStringValue],
144  ],
145  [
146  [$aStringValue, $cStringValue], [$aStringValue, $dStringValue],
147  [$bStringValue, $cStringValue], [$bStringValue, $dStringValue],
148  ],
149  ],
150  'mixed items' => [
151  [
152  [$aStringValue, 'a', 1],
153  [$bStringValue, 'b', 2],
154  ],
155  [
156  [$aStringValue, $bStringValue], [$aStringValue, 'b'], [$aStringValue, 2],
157  ['a', $bStringValue], ['a', 'b'], ['a', 2],
158  [1, $bStringValue], [1, 'b'], [1, 2],
159  ],
160  ],
161  'string items in ArrayObject' => [
162  [
163  new \ArrayObject(['a', 'b']),
164  new \ArrayObject(['c', 'd']),
165  new \ArrayObject(['e', 'f']),
166  ],
167  [
168  ['a', 'c', 'e'], ['a', 'c', 'f'], ['a', 'd', 'e'], ['a', 'd', 'f'],
169  ['b', 'c', 'e'], ['b', 'c', 'f'], ['b', 'd', 'e'], ['b', 'd', 'f'],
170  ],
171  ],
172  'string items with invalid invocation' => [
173  [
174  'a', 'b',
175  ],
176  1578164101,
177  ],
178  'object::__toString() items with invalid invocation' => [
179  [
180  new ‪StringValue('b'),
181  new ‪StringValue('c'),
182  new ‪StringValue('d'),
183  ],
184  1578164101,
185  ],
186  ];
187  }
188 
196  public function ‪meltArrayItemsIsExecuted(array $payload, $expectation): void
197  {
198  if (is_int($expectation)) {
199  $this->expectException(\LogicException::class);
200  $this->expectExceptionCode($expectation);
201  }
202  self::assertSame($expectation, ‪PermutationUtility::meltArrayItems($payload));
203  }
204 }
‪TYPO3\CMS\Core\Utility\PermutationUtility\meltStringItems
‪static array meltStringItems(array $payload, string $previousResult='')
Definition: PermutationUtility.php:36
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\PermutationUtilityTest\meltArrayItemsDataProvider
‪meltArrayItemsDataProvider()
Definition: PermutationUtilityTest.php:121
‪TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\StringValue
Definition: StringValue.php:21
‪TYPO3\CMS\Core\Utility\PermutationUtility
Definition: PermutationUtility.php:24
‪TYPO3\CMS\Core\Utility\PermutationUtility\meltArrayItems
‪static array meltArrayItems(array $payload, array $previousResult=[])
Definition: PermutationUtility.php:66
‪TYPO3\CMS\Core\Tests\Unit\Utility\PermutationUtilityTest\meltStringItemsDataProvider
‪meltStringItemsDataProvider()
Definition: PermutationUtilityTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Utility\PermutationUtilityTest\meltArrayItemsIsExecuted
‪meltArrayItemsIsExecuted(array $payload, $expectation)
Definition: PermutationUtilityTest.php:196
‪TYPO3\CMS\Core\Tests\Unit\Utility\PermutationUtilityTest\meltStringItemsIsExecuted
‪meltStringItemsIsExecuted(array $payload, $expectation)
Definition: PermutationUtilityTest.php:112
‪TYPO3\CMS\Core\Tests\Unit\Utility\PermutationUtilityTest
Definition: PermutationUtilityTest.php:28