[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / UnitDeprecated / Package / DependencyResolverTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Package;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Package\DependencyResolver;
18 use TYPO3\CMS\Core\Service\DependencyOrderingService;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class DependencyResolverTest extends UnitTestCase
25 {
26 /**
27 * @test
28 * @param array $unsortedPackageStatesConfiguration
29 * @param array $frameworkPackageKeys
30 * @param array $expectedGraph
31 * @dataProvider buildDependencyGraphBuildsCorrectGraphDataProvider
32 */
33 public function buildDependencyGraphBuildsCorrectGraph(array $unsortedPackageStatesConfiguration, array $frameworkPackageKeys, array $expectedGraph)
34 {
35 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $dependencyResolver */
36 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
37 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
38 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
39 $dependencyGraph = $dependencyResolver->_call('buildDependencyGraph', $unsortedPackageStatesConfiguration);
40
41 $this->assertEquals($expectedGraph, $dependencyGraph);
42 }
43
44 /**
45 * @test
46 * @dataProvider packageSortingDataProvider
47 * @param array $unsortedPackageStatesConfiguration
48 * @param array $frameworkPackageKeys
49 * @param array $expectedSortedPackageStatesConfiguration
50 */
51 public function sortPackageStatesConfigurationByDependencyMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays($unsortedPackageStatesConfiguration, $frameworkPackageKeys, $expectedSortedPackageKeys)
52 {
53 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $dependencyResolver */
54 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
55 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
56 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
57 $sortedPackageKeys = $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
58
59 $this->assertEquals($expectedSortedPackageKeys, $sortedPackageKeys, 'The package states configurations have not been ordered according to their dependencies!');
60 }
61
62 /**
63 * @test
64 */
65 public function sortPackageStatesConfigurationByDependencyThrowsExceptionWhenCycleDetected()
66 {
67 $unsortedPackageStatesConfiguration = [
68 'A' => [
69 'dependencies' => ['B'],
70 ],
71 'B' => [
72 'dependencies' => ['A']
73 ],
74 ];
75
76 $this->expectException(\UnexpectedValueException::class);
77 $this->expectExceptionCode(1381960494);
78
79 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $dependencyResolver */
80 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
81 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
82 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn([]);
83 $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
84 }
85
86 /**
87 * @return array
88 */
89 public function buildDependencyGraphBuildsCorrectGraphDataProvider()
90 {
91 return [
92 'TYPO3 Flow Packages' => [
93 [
94 'TYPO3.Flow' => [
95 'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
96 ],
97 'Doctrine.ORM' => [
98 'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
99 ],
100 'Doctrine.Common' => [
101 'dependencies' => []
102 ],
103 'Doctrine.DBAL' => [
104 'dependencies' => ['Doctrine.Common']
105 ],
106 'Symfony.Component.Yaml' => [
107 'dependencies' => []
108 ],
109 ],
110 [
111 'Doctrine.Common'
112 ],
113 [
114 'TYPO3.Flow' => [
115 'TYPO3.Flow' => false,
116 'Doctrine.ORM' => true,
117 'Doctrine.Common' => true,
118 'Doctrine.DBAL' => true,
119 'Symfony.Component.Yaml' => true,
120 ],
121 'Doctrine.ORM' => [
122 'TYPO3.Flow' => false,
123 'Doctrine.ORM' => false,
124 'Doctrine.Common' => true,
125 'Doctrine.DBAL' => true,
126 'Symfony.Component.Yaml' => false,
127 ],
128 'Doctrine.Common' => [
129 'TYPO3.Flow' => false,
130 'Doctrine.ORM' => false,
131 'Doctrine.Common' => false,
132 'Doctrine.DBAL' => false,
133 'Symfony.Component.Yaml' => false,
134 ],
135 'Doctrine.DBAL' => [
136 'TYPO3.Flow' => false,
137 'Doctrine.ORM' => false,
138 'Doctrine.Common' => true,
139 'Doctrine.DBAL' => false,
140 'Symfony.Component.Yaml' => false,
141 ],
142 'Symfony.Component.Yaml' => [
143 'TYPO3.Flow' => false,
144 'Doctrine.ORM' => false,
145 'Doctrine.Common' => true,
146 'Doctrine.DBAL' => false,
147 'Symfony.Component.Yaml' => false,
148 ],
149 ],
150 ],
151 'TYPO3 CMS Extensions' => [
152 [
153 'core' => [
154 'dependencies' => [],
155 ],
156 'setup' => [
157 'dependencies' => ['core'],
158 ],
159 'openid' => [
160 'dependencies' => ['core', 'setup']
161 ],
162 'news' => [
163 'dependencies' => ['extbase'],
164 ],
165 'extbase' => [
166 'dependencies' => ['core'],
167 ],
168 'pt_extbase' => [
169 'dependencies' => ['extbase'],
170 ],
171 'foo' => [
172 'dependencies' => [],
173 ],
174 ],
175 [
176 'core',
177 'setup',
178 'openid',
179 'extbase'
180 ],
181 [
182 'core' => [
183 'core' => false,
184 'setup' => false,
185 'openid' => false,
186 'news' => false,
187 'extbase' => false,
188 'pt_extbase' => false,
189 'foo' => false
190 ],
191 'setup' => [
192 'core' => true,
193 'setup' => false,
194 'openid' => false,
195 'news' => false,
196 'extbase' => false,
197 'pt_extbase' => false,
198 'foo' => false
199 ],
200 'openid' => [
201 'core' => true,
202 'setup' => true,
203 'openid' => false,
204 'news' => false,
205 'extbase' => false,
206 'pt_extbase' => false,
207 'foo' => false
208 ],
209 'news' => [
210 'core' => false,
211 'setup' => false,
212 'openid' => true,
213 'news' => false,
214 'extbase' => true,
215 'pt_extbase' => false,
216 'foo' => false
217 ],
218 'extbase' => [
219 'core' => true,
220 'setup' => false,
221 'openid' => false,
222 'news' => false,
223 'extbase' => false,
224 'pt_extbase' => false,
225 'foo' => false
226 ],
227 'pt_extbase' => [
228 'core' => false,
229 'setup' => false,
230 'openid' => true,
231 'news' => false,
232 'extbase' => true,
233 'pt_extbase' => false,
234 'foo' => false
235 ],
236 'foo' => [
237 'core' => false,
238 'setup' => false,
239 'openid' => true,
240 'news' => false,
241 'extbase' => true,
242 'pt_extbase' => false,
243 'foo' => false
244 ],
245 ],
246 ],
247 'Dummy Packages' => [
248 [
249 'A' => [
250 'dependencies' => ['B', 'D', 'C'],
251 ],
252 'B' => [
253 'dependencies' => []
254 ],
255 'C' => [
256 'dependencies' => ['E']
257 ],
258 'D' => [
259 'dependencies' => ['E'],
260 ],
261 'E' => [
262 'dependencies' => [],
263 ],
264 'F' => [
265 'dependencies' => [],
266 ],
267 ],
268 [
269 'B',
270 'C',
271 'E'
272 ],
273 [
274 'A' => [
275 'A' => false,
276 'B' => true,
277 'C' => true,
278 'D' => true,
279 'E' => false,
280 'F' => false,
281 ],
282 'B' => [
283 'A' => false,
284 'B' => false,
285 'C' => false,
286 'D' => false,
287 'E' => false,
288 'F' => false,
289 ],
290 'C' => [
291 'A' => false,
292 'B' => false,
293 'C' => false,
294 'D' => false,
295 'E' => true,
296 'F' => false,
297 ],
298 'D' => [
299 'A' => false,
300 'B' => true,
301 'C' => true,
302 'D' => false,
303 'E' => false,
304 'F' => false,
305 ],
306 'E' => [
307 'A' => false,
308 'B' => false,
309 'C' => false,
310 'D' => false,
311 'E' => false,
312 'F' => false,
313 ],
314 'F' => [
315 'A' => false,
316 'B' => true,
317 'C' => true,
318 'D' => false,
319 'E' => false,
320 'F' => false,
321 ],
322 ],
323 ],
324 ];
325 }
326
327 /**
328 * @return array
329 */
330 public function packageSortingDataProvider()
331 {
332 return [
333 'TYPO3 Flow Packages' => [
334 [
335 'TYPO3.Flow' => [
336 'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
337 ],
338 'Doctrine.ORM' => [
339 'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
340 ],
341 'Doctrine.Common' => [
342 'dependencies' => []
343 ],
344 'Doctrine.DBAL' => [
345 'dependencies' => ['Doctrine.Common']
346 ],
347 'Symfony.Component.Yaml' => [
348 'dependencies' => []
349 ],
350 ],
351 [
352 'Doctrine.Common'
353 ],
354 [
355 'Doctrine.Common',
356 'Doctrine.DBAL',
357 'Doctrine.ORM',
358 'Symfony.Component.Yaml',
359 'TYPO3.Flow',
360 ],
361 ],
362 'TYPO3 CMS Extensions' => [
363 [
364 'core' => [
365 'dependencies' => [],
366 ],
367 'setup' => [
368 'dependencies' => ['core'],
369 ],
370 'openid' => [
371 'dependencies' => ['core', 'setup']
372 ],
373 'news' => [
374 'dependencies' => ['extbase'],
375 ],
376 'extbase' => [
377 'dependencies' => ['core'],
378 ],
379 'pt_extbase' => [
380 'dependencies' => ['extbase'],
381 ],
382 'foo' => [
383 'dependencies' => [],
384 ],
385 ],
386 [
387 'core',
388 'setup',
389 'openid',
390 'extbase'
391 ],
392 [
393 'core',
394 'setup',
395 'openid',
396 'extbase',
397 'foo',
398 'news',
399 'pt_extbase',
400 ],
401 ],
402 'Dummy Packages' => [
403 [
404 'A' => [
405 'dependencies' => ['B', 'D', 'C'],
406 ],
407 'B' => [
408 'dependencies' => []
409 ],
410 'C' => [
411 'dependencies' => ['E']
412 ],
413 'D' => [
414 'dependencies' => ['E'],
415 ],
416 'E' => [
417 'dependencies' => [],
418 ],
419 'F' => [
420 'dependencies' => [],
421 ],
422 ],
423 [
424 'B',
425 'C',
426 'E'
427 ],
428 [
429 'E',
430 'C',
431 'B',
432 'D',
433 'A',
434 'F',
435 ],
436 ],
437 ];
438 }
439 }