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