TYPO3 CMS  TYPO3_7-6
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 
20 
25 {
33  public function buildDependencyGraphBuildsCorrectGraph(array $unsortedPackageStatesConfiguration, array $frameworkPackageKeys, array $expectedGraph)
34  {
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 
51  public function sortPackageStatesConfigurationByDependencyMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays($unsortedPackageStatesConfiguration, $frameworkPackageKeys, $expectedSortedPackageStatesConfiguration)
52  {
54  $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, ['findFrameworkPackages']);
55  $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
56  $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
57  $sortedPackageStatesConfiguration = $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
58 
59  $this->assertEquals($expectedSortedPackageStatesConfiguration, $sortedPackageStatesConfiguration, 'The package states configurations have not been ordered according to their dependencies!');
60  }
61 
66  public function sortPackageStatesConfigurationByDependencyThrowsExceptionWhenCycleDetected()
67  {
68  $unsortedPackageStatesConfiguration = [
69  'A' => [
70  'state' => 'active',
71  'dependencies' => ['B'],
72  ],
73  'B' => [
74  'state' => 'active',
75  'dependencies' => ['A']
76  ],
77  ];
78 
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 
90  {
91  return [
92  'TYPO3 Flow Packages' => [
93  [
94  'TYPO3.Flow' => [
95  'state' => 'active',
96  'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
97  ],
98  'Doctrine.ORM' => [
99  'state' => 'active',
100  'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
101  ],
102  'Doctrine.Common' => [
103  'state' => 'active',
104  'dependencies' => []
105  ],
106  'Doctrine.DBAL' => [
107  'state' => 'active',
108  'dependencies' => ['Doctrine.Common']
109  ],
110  'Symfony.Component.Yaml' => [
111  'state' => 'active',
112  'dependencies' => []
113  ],
114  ],
115  [
116  'Doctrine.Common'
117  ],
118  [
119  'TYPO3.Flow' => [
120  'TYPO3.Flow' => false,
121  'Doctrine.ORM' => true,
122  'Doctrine.Common' => true,
123  'Doctrine.DBAL' => true,
124  'Symfony.Component.Yaml' => true,
125  ],
126  'Doctrine.ORM' => [
127  'TYPO3.Flow' => false,
128  'Doctrine.ORM' => false,
129  'Doctrine.Common' => true,
130  'Doctrine.DBAL' => true,
131  'Symfony.Component.Yaml' => false,
132  ],
133  'Doctrine.Common' => [
134  'TYPO3.Flow' => false,
135  'Doctrine.ORM' => false,
136  'Doctrine.Common' => false,
137  'Doctrine.DBAL' => false,
138  'Symfony.Component.Yaml' => false,
139  ],
140  'Doctrine.DBAL' => [
141  'TYPO3.Flow' => false,
142  'Doctrine.ORM' => false,
143  'Doctrine.Common' => true,
144  'Doctrine.DBAL' => false,
145  'Symfony.Component.Yaml' => false,
146  ],
147  'Symfony.Component.Yaml' => [
148  'TYPO3.Flow' => false,
149  'Doctrine.ORM' => false,
150  'Doctrine.Common' => true,
151  'Doctrine.DBAL' => false,
152  'Symfony.Component.Yaml' => false,
153  ],
154  ],
155  ],
156  'TYPO3 CMS Extensions' => [
157  [
158  'core' => [
159  'state' => 'active',
160  'dependencies' => [],
161  ],
162  'setup' => [
163  'state' => 'active',
164  'dependencies' => ['core'],
165  ],
166  'openid' => [
167  'state' => 'active',
168  'dependencies' => ['core', 'setup']
169  ],
170  'news' => [
171  'state' => 'active',
172  'dependencies' => ['extbase'],
173  ],
174  'extbase' => [
175  'state' => 'active',
176  'dependencies' => ['core'],
177  ],
178  'pt_extbase' => [
179  'state' => 'active',
180  'dependencies' => ['extbase'],
181  ],
182  'foo' => [
183  'state' => 'active',
184  'dependencies' => [],
185  ],
186  ],
187  [
188  'core', 'setup', 'openid', 'extbase'
189  ],
190  [
191  'core' => [
192  'core' => false,
193  'setup' => false,
194  'openid' => false,
195  'news' => false,
196  'extbase' => false,
197  'pt_extbase' => false,
198  'foo' => false
199  ],
200  'setup' => [
201  'core' => true,
202  'setup' => false,
203  'openid' => false,
204  'news' => false,
205  'extbase' => false,
206  'pt_extbase' => false,
207  'foo' => false
208  ],
209  'openid' => [
210  'core' => true,
211  'setup' => true,
212  'openid' => false,
213  'news' => false,
214  'extbase' => false,
215  'pt_extbase' => false,
216  'foo' => false
217  ],
218  'news' => [
219  'core' => false,
220  'setup' => false,
221  'openid' => true,
222  'news' => false,
223  'extbase' => true,
224  'pt_extbase' => false,
225  'foo' => false
226  ],
227  'extbase' => [
228  'core' => true,
229  'setup' => false,
230  'openid' => false,
231  'news' => false,
232  'extbase' => false,
233  'pt_extbase' => false,
234  'foo' => false
235  ],
236  'pt_extbase' => [
237  'core' => false,
238  'setup' => false,
239  'openid' => true,
240  'news' => false,
241  'extbase' => true,
242  'pt_extbase' => false,
243  'foo' => false
244  ],
245  'foo' => [
246  'core' => false,
247  'setup' => false,
248  'openid' => true,
249  'news' => false,
250  'extbase' => true,
251  'pt_extbase' => false,
252  'foo' => false
253  ],
254  ],
255  ],
256  'Dummy Packages' => [
257  [
258  'A' => [
259  'state' => 'active',
260  'dependencies' => ['B', 'D', 'C'],
261  ],
262  'B' => [
263  'state' => 'active',
264  'dependencies' => []
265  ],
266  'C' => [
267  'state' => 'active',
268  'dependencies' => ['E']
269  ],
270  'D' => [
271  'state' => 'active',
272  'dependencies' => ['E'],
273  ],
274  'E' => [
275  'state' => 'active',
276  'dependencies' => [],
277  ],
278  'F' => [
279  'state' => 'active',
280  'dependencies' => [],
281  ],
282  ],
283  [
284  'B', 'C', 'E'
285  ],
286  [
287  'A' => [
288  'A' => false,
289  'B' => true,
290  'C' => true,
291  'D' => true,
292  'E' => false,
293  'F' => false,
294  ],
295  'B' => [
296  'A' => false,
297  'B' => false,
298  'C' => false,
299  'D' => false,
300  'E' => false,
301  'F' => false,
302  ],
303  'C' => [
304  'A' => false,
305  'B' => false,
306  'C' => false,
307  'D' => false,
308  'E' => true,
309  'F' => false,
310  ],
311  'D' => [
312  'A' => false,
313  'B' => true,
314  'C' => true,
315  'D' => false,
316  'E' => false,
317  'F' => false,
318  ],
319  'E' => [
320  'A' => false,
321  'B' => false,
322  'C' => false,
323  'D' => false,
324  'E' => false,
325  'F' => false,
326  ],
327  'F' => [
328  'A' => false,
329  'B' => true,
330  'C' => true,
331  'D' => false,
332  'E' => false,
333  'F' => false,
334  ],
335  ],
336  ],
337  ];
338  }
339 
343  public function packageSortingDataProvider()
344  {
345  return [
346  'TYPO3 Flow Packages' => [
347  [
348  'TYPO3.Flow' => [
349  'state' => 'active',
350  'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
351  ],
352  'Doctrine.ORM' => [
353  'state' => 'active',
354  'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
355  ],
356  'Doctrine.Common' => [
357  'state' => 'active',
358  'dependencies' => []
359  ],
360  'Doctrine.DBAL' => [
361  'state' => 'active',
362  'dependencies' => ['Doctrine.Common']
363  ],
364  'Symfony.Component.Yaml' => [
365  'state' => 'active',
366  'dependencies' => []
367  ],
368  ],
369  [
370  'Doctrine.Common'
371  ],
372  [
373  'Doctrine.Common' => [
374  'state' => 'active',
375  'dependencies' => []
376  ],
377  'Doctrine.DBAL' => [
378  'state' => 'active',
379  'dependencies' => ['Doctrine.Common']
380  ],
381  'Doctrine.ORM' => [
382  'state' => 'active',
383  'dependencies' => ['Doctrine.Common', 'Doctrine.DBAL']
384  ],
385  'Symfony.Component.Yaml' => [
386  'state' => 'active',
387  'dependencies' => []
388  ],
389  'TYPO3.Flow' => [
390  'state' => 'active',
391  'dependencies' => ['Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM']
392  ],
393  ],
394  ],
395  'TYPO3 CMS Extensions' => [
396  [
397  'core' => [
398  'state' => 'active',
399  'dependencies' => [],
400  ],
401  'setup' => [
402  'state' => 'active',
403  'dependencies' => ['core'],
404  ],
405  'openid' => [
406  'state' => 'active',
407  'dependencies' => ['core', 'setup']
408  ],
409  'news' => [
410  'state' => 'active',
411  'dependencies' => ['extbase'],
412  ],
413  'extbase' => [
414  'state' => 'active',
415  'dependencies' => ['core'],
416  ],
417  'pt_extbase' => [
418  'state' => 'active',
419  'dependencies' => ['extbase'],
420  ],
421  'foo' => [
422  'state' => 'active',
423  'dependencies' => [],
424  ],
425  ],
426  [
427  'core', 'setup', 'openid', 'extbase'
428  ],
429  [
430  'core' => [
431  'state' => 'active',
432  'dependencies' => [],
433  ],
434  'setup' => [
435  'state' => 'active',
436  'dependencies' => ['core'],
437  ],
438  'openid' => [
439  'state' => 'active',
440  'dependencies' => ['core', 'setup']
441  ],
442  'extbase' => [
443  'state' => 'active',
444  'dependencies' => ['core'],
445  ],
446  'foo' => [
447  'state' => 'active',
448  'dependencies' => [],
449  ],
450  'pt_extbase' => [
451  'state' => 'active',
452  'dependencies' => ['extbase'],
453  ],
454  'news' => [
455  'state' => 'active',
456  'dependencies' => ['extbase'],
457  ],
458  ],
459  ],
460  'Dummy Packages' => [
461  [
462  'A' => [
463  'state' => 'active',
464  'dependencies' => ['B', 'D', 'C'],
465  ],
466  'B' => [
467  'state' => 'active',
468  'dependencies' => []
469  ],
470  'C' => [
471  'state' => 'active',
472  'dependencies' => ['E']
473  ],
474  'D' => [
475  'state' => 'active',
476  'dependencies' => ['E'],
477  ],
478  'E' => [
479  'state' => 'active',
480  'dependencies' => [],
481  ],
482  'F' => [
483  'state' => 'active',
484  'dependencies' => [],
485  ],
486  ],
487  [
488  'B', 'C', 'E'
489  ],
490  [
491  'B' => [
492  'state' => 'active',
493  'dependencies' => [],
494  ],
495  'E' => [
496  'state' => 'active',
497  'dependencies' => [],
498  ],
499  'C' => [
500  'state' => 'active',
501  'dependencies' => ['E'],
502  ],
503  'F' => [
504  'state' => 'active',
505  'dependencies' => [],
506  ],
507  'D' => [
508  'state' => 'active',
509  'dependencies' => ['E'],
510  ],
511  'A' => [
512  'state' => 'active',
513  'dependencies' => ['B', 'D', 'C'],
514  ],
515  ],
516  ],
517  ];
518  }
519 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)