1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Bundle\ThemeBundle\Loader; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyChecker; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyCheckerInterface; |
19
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyFoundException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @mixin CircularDependencyChecker |
23
|
|
|
* |
24
|
|
|
* @author Kamil Kokot <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class CircularDependencyCheckerSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function it_is_initializable() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\Loader\CircularDependencyChecker'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_implements_circular_dependency_checker_interface() |
34
|
|
|
{ |
35
|
|
|
$this->shouldImplement(CircularDependencyCheckerInterface::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_does_not_find_circular_dependency_if_checking_a_theme_without_any_parents( |
39
|
|
|
ThemeInterface $theme |
40
|
|
|
) { |
41
|
|
|
$theme->getParents()->willReturn([]); |
42
|
|
|
|
43
|
|
|
$this->check($theme); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_does_not_find_circular_dependency_if_theme_parents_are_not_cycled( |
47
|
|
|
ThemeInterface $firstTheme, |
48
|
|
|
ThemeInterface $secondTheme, |
49
|
|
|
ThemeInterface $thirdTheme, |
50
|
|
|
ThemeInterface $fourthTheme |
51
|
|
|
) { |
52
|
|
|
$firstTheme->getParents()->willReturn([$secondTheme, $thirdTheme]); |
53
|
|
|
$secondTheme->getParents()->willReturn([$thirdTheme, $fourthTheme]); |
54
|
|
|
$thirdTheme->getParents()->willReturn([$fourthTheme]); |
55
|
|
|
$fourthTheme->getParents()->willReturn([]); |
56
|
|
|
|
57
|
|
|
$this->check($firstTheme); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_finds_circular_dependency_if_theme_parents_are_cycled( |
61
|
|
|
ThemeInterface $firstTheme, |
62
|
|
|
ThemeInterface $secondTheme, |
63
|
|
|
ThemeInterface $thirdTheme, |
64
|
|
|
ThemeInterface $fourthTheme |
65
|
|
|
) { |
66
|
|
|
$firstTheme->getParents()->willReturn([$secondTheme, $thirdTheme]); |
67
|
|
|
$secondTheme->getParents()->willReturn([$thirdTheme]); |
68
|
|
|
$thirdTheme->getParents()->willReturn([$fourthTheme]); |
69
|
|
|
$fourthTheme->getParents()->willReturn([$secondTheme]); |
70
|
|
|
|
71
|
|
|
$firstTheme->getName()->willReturn('first/theme'); |
72
|
|
|
$secondTheme->getName()->willReturn('second/theme'); |
73
|
|
|
$thirdTheme->getName()->willReturn('third/theme'); |
74
|
|
|
$fourthTheme->getName()->willReturn('fourth/theme'); |
75
|
|
|
|
76
|
|
|
$this |
77
|
|
|
->shouldThrow(CircularDependencyFoundException::class) |
78
|
|
|
->during('check', [$firstTheme]) |
79
|
|
|
; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|