TYPO3 CMS  TYPO3_8-7
DependencyResolverTest.php
Go to the documentation of this file.
1 <?php
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 
19 
23 class DependencyResolverTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
32  public function buildDependencyGraphBuildsCorrectGraph(array $unsortedPackageStatesConfiguration, array $frameworkPackageKeys, array $expectedGraph)
33  {
35  $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
36  $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
37  $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
38  $dependencyGraph = $dependencyResolver->_call('buildDependencyGraph', $unsortedPackageStatesConfiguration);
39 
40  $this->assertEquals($expectedGraph, $dependencyGraph);
41  }
42 
50  public function sortPackageStatesConfigurationByDependencyMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays($unsortedPackageStatesConfiguration, $frameworkPackageKeys, $expectedSortedPackageKeys)
51  {
53  $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
54  $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
55  $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
56  $sortedPackageKeys = $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
57 
58  $this->assertEquals($expectedSortedPackageKeys, $sortedPackageKeys, 'The package states configurations have not been ordered according to their dependencies!');
59  }
60 
64  public function sortPackageStatesConfigurationByDependencyThrowsExceptionWhenCycleDetected()
65  {
66  $unsortedPackageStatesConfiguration = [
67  'A' => [
68  'dependencies' => ['B'],
69  ],
70  'B' => [
71  'dependencies' => ['A']
72  ],
73  ];
74 
75  $this->expectException(\UnexpectedValueException::class);
76  $this->expectExceptionCode(1381960494);
77 
79  $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
80  $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
81  $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn([]);
82  $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
83  }
84 
89  {
90  return [
91  'TYPO3 Flow Packages' => [
92  [
93  'TYPO3.Flow' => [
94  'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
95  ],
96  'Doctrine.ORM' => [
97  'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
98  ],
99  'Doctrine.Common' => [
100  'dependencies' => []
101  ],
102  'Doctrine.DBAL' => [
103  'dependencies' => ['Doctrine.Common']
104  ],
105  'Symfony.Component.Yaml' => [
106  'dependencies' => []
107  ],
108  ],
109  [
110  'Doctrine.Common'
111  ],
112  [
113  'TYPO3.Flow' => [
114  'TYPO3.Flow' => false,
115  'Doctrine.ORM' => true,
116  'Doctrine.Common' => true,
117  'Doctrine.DBAL' => true,
118  'Symfony.Component.Yaml' => true,
119  ],
120  'Doctrine.ORM' => [
121  'TYPO3.Flow' => false,
122  'Doctrine.ORM' => false,
123  'Doctrine.Common' => true,
124  'Doctrine.DBAL' => true,
125  'Symfony.Component.Yaml' => false,
126  ],
127  'Doctrine.Common' => [
128  'TYPO3.Flow' => false,
129  'Doctrine.ORM' => false,
130  'Doctrine.Common' => false,
131  'Doctrine.DBAL' => false,
132  'Symfony.Component.Yaml' => false,
133  ],
134  'Doctrine.DBAL' => [
135  'TYPO3.Flow' => false,
136  'Doctrine.ORM' => false,
137  'Doctrine.Common' => true,
138  'Doctrine.DBAL' => false,
139  'Symfony.Component.Yaml' => false,
140  ],
141  'Symfony.Component.Yaml' => [
142  'TYPO3.Flow' => false,
143  'Doctrine.ORM' => false,
144  'Doctrine.Common' => true,
145  'Doctrine.DBAL' => false,
146  'Symfony.Component.Yaml' => false,
147  ],
148  ],
149  ],
150  'TYPO3 CMS Extensions' => [
151  [
152  'core' => [
153  'dependencies' => [],
154  ],
155  'setup' => [
156  'dependencies' => ['core'],
157  ],
158  'openid' => [
159  'dependencies' => ['core', 'setup']
160  ],
161  'news' => [
162  'dependencies' => ['extbase'],
163  ],
164  'extbase' => [
165  'dependencies' => ['core'],
166  ],
167  'pt_extbase' => [
168  'dependencies' => ['extbase'],
169  ],
170  'foo' => [
171  'dependencies' => [],
172  ],
173  ],
174  [
175  'core', 'setup', 'openid', 'extbase'
176  ],
177  [
178  'core' => [
179  'core' => false,
180  'setup' => false,
181  'openid' => false,
182  'news' => false,
183  'extbase' => false,
184  'pt_extbase' => false,
185  'foo' => false
186  ],
187  'setup' => [
188  'core' => true,
189  'setup' => false,
190  'openid' => false,
191  'news' => false,
192  'extbase' => false,
193  'pt_extbase' => false,
194  'foo' => false
195  ],
196  'openid' => [
197  'core' => true,
198  'setup' => true,
199  'openid' => false,
200  'news' => false,
201  'extbase' => false,
202  'pt_extbase' => false,
203  'foo' => false
204  ],
205  'news' => [
206  'core' => false,
207  'setup' => false,
208  'openid' => true,
209  'news' => false,
210  'extbase' => true,
211  'pt_extbase' => false,
212  'foo' => false
213  ],
214  'extbase' => [
215  'core' => true,
216  'setup' => false,
217  'openid' => false,
218  'news' => false,
219  'extbase' => false,
220  'pt_extbase' => false,
221  'foo' => false
222  ],
223  'pt_extbase' => [
224  'core' => false,
225  'setup' => false,
226  'openid' => true,
227  'news' => false,
228  'extbase' => true,
229  'pt_extbase' => false,
230  'foo' => false
231  ],
232  'foo' => [
233  'core' => false,
234  'setup' => false,
235  'openid' => true,
236  'news' => false,
237  'extbase' => true,
238  'pt_extbase' => false,
239  'foo' => false
240  ],
241  ],
242  ],
243  'Dummy Packages' => [
244  [
245  'A' => [
246  'dependencies' => ['B', 'D', 'C'],
247  ],
248  'B' => [
249  'dependencies' => []
250  ],
251  'C' => [
252  'dependencies' => ['E']
253  ],
254  'D' => [
255  'dependencies' => ['E'],
256  ],
257  'E' => [
258  'dependencies' => [],
259  ],
260  'F' => [
261  'dependencies' => [],
262  ],
263  ],
264  [
265  'B', 'C', 'E'
266  ],
267  [
268  'A' => [
269  'A' => false,
270  'B' => true,
271  'C' => true,
272  'D' => true,
273  'E' => false,
274  'F' => false,
275  ],
276  'B' => [
277  'A' => false,
278  'B' => false,
279  'C' => false,
280  'D' => false,
281  'E' => false,
282  'F' => false,
283  ],
284  'C' => [
285  'A' => false,
286  'B' => false,
287  'C' => false,
288  'D' => false,
289  'E' => true,
290  'F' => false,
291  ],
292  'D' => [
293  'A' => false,
294  'B' => true,
295  'C' => true,
296  'D' => false,
297  'E' => false,
298  'F' => false,
299  ],
300  'E' => [
301  'A' => false,
302  'B' => false,
303  'C' => false,
304  'D' => false,
305  'E' => false,
306  'F' => false,
307  ],
308  'F' => [
309  'A' => false,
310  'B' => true,
311  'C' => true,
312  'D' => false,
313  'E' => false,
314  'F' => false,
315  ],
316  ],
317  ],
318  ];
319  }
320 
324  public function packageSortingDataProvider()
325  {
326  return [
327  'TYPO3 Flow Packages' => [
328  [
329  'TYPO3.Flow' => [
330  'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
331  ],
332  'Doctrine.ORM' => [
333  'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
334  ],
335  'Doctrine.Common' => [
336  'dependencies' => []
337  ],
338  'Doctrine.DBAL' => [
339  'dependencies' => ['Doctrine.Common']
340  ],
341  'Symfony.Component.Yaml' => [
342  'dependencies' => []
343  ],
344  ],
345  [
346  'Doctrine.Common'
347  ],
348  [
349  'Doctrine.Common',
350  'Doctrine.DBAL',
351  'Doctrine.ORM',
352  'Symfony.Component.Yaml',
353  'TYPO3.Flow',
354  ],
355  ],
356  'TYPO3 CMS Extensions' => [
357  [
358  'core' => [
359  'dependencies' => [],
360  ],
361  'setup' => [
362  'dependencies' => ['core'],
363  ],
364  'openid' => [
365  'dependencies' => ['core', 'setup']
366  ],
367  'news' => [
368  'dependencies' => ['extbase'],
369  ],
370  'extbase' => [
371  'dependencies' => ['core'],
372  ],
373  'pt_extbase' => [
374  'dependencies' => ['extbase'],
375  ],
376  'foo' => [
377  'dependencies' => [],
378  ],
379  ],
380  [
381  'core', 'setup', 'openid', 'extbase'
382  ],
383  [
384  'core',
385  'setup',
386  'openid',
387  'extbase',
388  'foo',
389  'news',
390  'pt_extbase',
391  ],
392  ],
393  'Dummy Packages' => [
394  [
395  'A' => [
396  'dependencies' => ['B', 'D', 'C'],
397  ],
398  'B' => [
399  'dependencies' => []
400  ],
401  'C' => [
402  'dependencies' => ['E']
403  ],
404  'D' => [
405  'dependencies' => ['E'],
406  ],
407  'E' => [
408  'dependencies' => [],
409  ],
410  'F' => [
411  'dependencies' => [],
412  ],
413  ],
414  [
415  'B', 'C', 'E'
416  ],
417  [
418  'E',
419  'C',
420  'B',
421  'D',
422  'A',
423  'F',
424  ],
425  ],
426  ];
427  }
428 }