Completed
Push — master ( 90ccc1...22512f )
by Kamil
35:43
created

it_provides_loaded_configuration_files()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
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\Filesystem;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\ThemeBundle\Loader\ConfigurationProviderInterface;
17
use Sylius\Bundle\ThemeBundle\Loader\Filesystem\FilesystemConfigurationProvider;
18
use Sylius\Bundle\ThemeBundle\Loader\LoaderInterface;
19
use Sylius\Bundle\ThemeBundle\Locator\FileLocatorInterface;
20
use Symfony\Component\Config\Resource\ResourceInterface;
21
22
/**
23
 * @mixin FilesystemConfigurationProvider
24
 *
25
 * @author Kamil Kokot <[email protected]>
26
 */
27
class FilesystemConfigurationProviderSpec extends ObjectBehavior
28
{
29
    function let(FileLocatorInterface $fileLocator, LoaderInterface $loader)
30
    {
31
        $this->beConstructedWith($fileLocator, $loader, 'configurationfile.json');
32
    }
33
34
    function it_is_initializable()
35
    {
36
        $this->shouldHaveType('Sylius\Bundle\ThemeBundle\Loader\Filesystem\FilesystemConfigurationProvider');
37
    }
38
39
    function it_implements_configuration_provider_interface()
40
    {
41
        $this->shouldImplement(ConfigurationProviderInterface::class);
42
    }
43
44
    function it_provides_loaded_configuration_files(FileLocatorInterface $fileLocator, LoaderInterface $loader)
45
    {
46
        $fileLocator->locateFilesNamed('configurationfile.json')->willReturn([
47
            '/cristopher/configurationfile.json',
48
            '/richard/configurationfile.json',
49
        ]);
50
51
        $loader->load('/cristopher/configurationfile.json')->willReturn(['name' => 'cristopher/sylus-theme']);
52
        $loader->load('/richard/configurationfile.json')->willReturn(['name' => 'richard/sylus-theme']);
53
54
        $this->getConfigurations()->shouldReturn([
55
            ['name' => 'cristopher/sylus-theme'],
56
            ['name' => 'richard/sylus-theme'],
57
        ]);
58
    }
59
60
    function it_provides_an_empty_array_if_there_were_no_themes_found(FileLocatorInterface $fileLocator)
61
    {
62
        $fileLocator->locateFilesNamed('configurationfile.json')->willThrow(\InvalidArgumentException::class);
63
64
        $this->getConfigurations()->shouldReturn([]);
65
    }
66
67
    function it_provides_a_list_of_symfony_config_resources_used(FileLocatorInterface $fileLocator)
68
    {
69
        $fileLocator->locateFilesNamed('configurationfile.json')->willReturn([
70
            '/cristopher/configurationfile.json',
71
            '/richard/configurationfile.json',
72
        ]);
73
74
        $this->getResources()->shouldHaveAllElementsOf(ResourceInterface::class);
75
    }
76
77
    function it_provides_an_empty_list_of_symfony_config_resources_used_if_there_arent_any_found(FileLocatorInterface $fileLocator)
78
    {
79
        $fileLocator->locateFilesNamed('configurationfile.json')->willThrow(\InvalidArgumentException::class);
80
81
        $this->getResources()->shouldReturn([]);
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function getMatchers()
88
    {
89
        return [
90
            'haveAllElementsOf' => function (array $subject, $type) {
91
                foreach ($subject as $element) {
92
                    if ($type === get_class($element) || is_subclass_of($element, $type)) {
93
                        return true;
94
                    }
95
                }
96
97
                return false;
98
            },
99
        ];
100
    }
101
}
102