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\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\ThemeBundle\DependencyInjection\Compiler\ThemeRepositoryPass; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
18
|
|
|
use Symfony\Component\Config\FileLocatorInterface; |
19
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @mixin ThemeRepositoryPass |
26
|
|
|
* |
27
|
|
|
* @author Kamil Kokot <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class ThemeRepositoryPassSpec extends ObjectBehavior |
30
|
|
|
{ |
31
|
|
|
function it_is_initializable() |
32
|
|
|
{ |
33
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\DependencyInjection\Compiler\ThemeRepositoryPass'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_implements_compiler_pass_interface() |
37
|
|
|
{ |
38
|
|
|
$this->shouldImplement(CompilerPassInterface::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_adds_themes_to_theme_repository( |
42
|
|
|
ContainerBuilder $containerBuilder, |
43
|
|
|
Definition $themeRepositoryDefinition, |
44
|
|
|
LoaderInterface $themeLoader, |
45
|
|
|
FileLocatorInterface $themeLocator, |
46
|
|
|
ThemeInterface $theme |
47
|
|
|
) { |
48
|
|
|
$themeRepositoryDefinition->addArgument(Argument::type('array'))->shouldBeCalled(); |
49
|
|
|
|
50
|
|
|
$themeLocator->locate("theme.json", Argument::any(), false)->shouldBeCalled()->willReturn(["foo/bar/theme.json"]); |
51
|
|
|
|
52
|
|
|
$themeLoader->load("foo/bar/theme.json")->shouldBeCalled()->willReturn($theme); |
53
|
|
|
|
54
|
|
|
$containerBuilder->findDefinition("sylius.theme.repository")->shouldBeCalled()->willReturn($themeRepositoryDefinition); |
55
|
|
|
$containerBuilder->get("sylius.theme.locator")->shouldBeCalled()->willReturn($themeLocator); |
56
|
|
|
$containerBuilder->get("sylius.theme.loader")->shouldBeCalled()->willReturn($themeLoader); |
57
|
|
|
$containerBuilder->addResource(Argument::type('Symfony\Component\Config\Resource\FileResource'))->shouldBeCalled(); |
58
|
|
|
|
59
|
|
|
$this->process($containerBuilder); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function it_does_not_crash_if_themes_not_found( |
63
|
|
|
ContainerBuilder $containerBuilder, |
64
|
|
|
Definition $themeRepositoryDefinition, |
65
|
|
|
LoaderInterface $themeLoader, |
66
|
|
|
FileLocatorInterface $themeLocator |
67
|
|
|
) { |
68
|
|
|
$themeLocator->locate("theme.json", Argument::any(), false)->shouldBeCalled()->willThrow(new \InvalidArgumentException()); |
69
|
|
|
|
70
|
|
|
$containerBuilder->findDefinition("sylius.theme.repository")->shouldBeCalled()->willReturn($themeRepositoryDefinition); |
71
|
|
|
$containerBuilder->get("sylius.theme.locator")->shouldBeCalled()->willReturn($themeLocator); |
72
|
|
|
$containerBuilder->get("sylius.theme.loader")->shouldBeCalled()->willReturn($themeLoader); |
73
|
|
|
|
74
|
|
|
$this->process($containerBuilder); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|