|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\ThemeBundle\Locator; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Bundle\ThemeBundle\Locator\ResourceLocatorInterface; |
|
18
|
|
|
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException; |
|
19
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
|
20
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
21
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
22
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
23
|
|
|
|
|
24
|
|
|
final class BundleResourceLocatorSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
function let(Filesystem $filesystem, KernelInterface $kernel): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->beConstructedWith($filesystem, $kernel); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_implements_resource_locator_interface(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldImplement(ResourceLocatorInterface::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_locates_bundle_resource_using_path_derived_from_bundle_notation_and_symfony3_kernel_behaviour( |
|
37
|
|
|
Filesystem $filesystem, |
|
38
|
|
|
KernelInterface $kernel, |
|
39
|
|
|
ThemeInterface $theme, |
|
40
|
|
|
BundleInterface $childBundle, |
|
41
|
|
|
BundleInterface $parentBundle |
|
42
|
|
|
): void { |
|
43
|
|
|
$kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]); |
|
44
|
|
|
|
|
45
|
|
|
$childBundle->getName()->willReturn('ChildBundle'); |
|
46
|
|
|
$parentBundle->getName()->willReturn('ParentBundle'); |
|
47
|
|
|
|
|
48
|
|
|
$theme->getPath()->willReturn('/theme/path'); |
|
49
|
|
|
|
|
50
|
|
|
$filesystem->exists('/theme/path/ChildBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false); |
|
51
|
|
|
$filesystem->exists('/theme/path/ParentBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(true); |
|
52
|
|
|
|
|
53
|
|
|
$this->locateResource('@ParentBundle/Resources/views/Directory/index.html.twig', $theme)->shouldReturn('/theme/path/ParentBundle/views/Directory/index.html.twig'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
function it_locates_bundle_resource_using_path_derived_from_bundle_notation_and_symfony4_kernel_behaviour( |
|
57
|
|
|
Filesystem $filesystem, |
|
58
|
|
|
KernelInterface $kernel, |
|
59
|
|
|
ThemeInterface $theme, |
|
60
|
|
|
BundleInterface $justBundle |
|
61
|
|
|
): void { |
|
62
|
|
|
$kernel->getBundle('JustBundle', false)->willReturn($justBundle); |
|
63
|
|
|
|
|
64
|
|
|
$justBundle->getName()->willReturn('JustBundle'); |
|
65
|
|
|
|
|
66
|
|
|
$theme->getPath()->willReturn('/theme/path'); |
|
67
|
|
|
|
|
68
|
|
|
$filesystem->exists('/theme/path/JustBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(true); |
|
69
|
|
|
|
|
70
|
|
|
$this->locateResource('@JustBundle/Resources/views/Directory/index.html.twig', $theme)->shouldReturn('/theme/path/JustBundle/views/Directory/index.html.twig'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function it_throws_an_exception_if_resource_can_not_be_located_using_path_derived_from_bundle_notation( |
|
74
|
|
|
Filesystem $filesystem, |
|
75
|
|
|
KernelInterface $kernel, |
|
76
|
|
|
ThemeInterface $theme, |
|
77
|
|
|
BundleInterface $childBundle, |
|
78
|
|
|
BundleInterface $parentBundle |
|
79
|
|
|
): void { |
|
80
|
|
|
$kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]); |
|
81
|
|
|
|
|
82
|
|
|
$childBundle->getName()->willReturn('ChildBundle'); |
|
83
|
|
|
$parentBundle->getName()->willReturn('ParentBundle'); |
|
84
|
|
|
|
|
85
|
|
|
$theme->getName()->willReturn('theme/name'); |
|
86
|
|
|
$theme->getPath()->willReturn('/theme/path'); |
|
87
|
|
|
|
|
88
|
|
|
$filesystem->exists('/theme/path/ChildBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false); |
|
89
|
|
|
$filesystem->exists('/theme/path/ParentBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false); |
|
90
|
|
|
|
|
91
|
|
|
$this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/Directory/index.html.twig', $theme]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function it_locates_bundle_resource_using_path_derived_from_twig_namespaces( |
|
95
|
|
|
Filesystem $filesystem, |
|
96
|
|
|
ThemeInterface $theme |
|
97
|
|
|
): void { |
|
98
|
|
|
$theme->getPath()->willReturn('/theme/path'); |
|
99
|
|
|
|
|
100
|
|
|
$filesystem->exists('/theme/path/JustBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(true); |
|
101
|
|
|
|
|
102
|
|
|
$this->locateResource('@Just/Directory/index.html.twig', $theme)->shouldReturn('/theme/path/JustBundle/views/Directory/index.html.twig'); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function it_throws_an_exception_if_resource_can_not_be_located_using_path_derived_from_twig_namespaces( |
|
106
|
|
|
Filesystem $filesystem, |
|
107
|
|
|
ThemeInterface $theme |
|
108
|
|
|
): void { |
|
109
|
|
|
$theme->getName()->willReturn('theme/name'); |
|
110
|
|
|
$theme->getPath()->willReturn('/theme/path'); |
|
111
|
|
|
|
|
112
|
|
|
$filesystem->exists('/theme/path/JustBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false); |
|
113
|
|
|
|
|
114
|
|
|
$this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@Just/Directory/index.html.twig', $theme]); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
function it_throws_an_exception_if_resource_path_does_not_start_with_an_asperand(ThemeInterface $theme): void |
|
118
|
|
|
{ |
|
119
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('locateResource', ['ParentBundle/Resources/views/Directory/index.html.twig', $theme]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function it_throws_an_exception_if_resource_path_contains_two_dots_in_a_row(ThemeInterface $theme): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('locateResource', ['@ParentBundle/Resources/views/../views/Directory/index.html.twig', $theme]); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|