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 Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface; |
16
|
|
|
use Sylius\Bundle\ThemeBundle\Filesystem\FilesystemInterface; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\JsonThemeLoader; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
19
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @mixin JsonThemeLoader |
23
|
|
|
* |
24
|
|
|
* @author Kamil Kokot <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class JsonThemeLoaderSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(FilesystemInterface $filesystem, ThemeFactoryInterface $themeFactory) |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($filesystem, $themeFactory); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\Loader\JsonThemeLoader'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_loader_interface() |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(LoaderInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_loads_valid_theme_file(FilesystemInterface $filesystem, ThemeFactoryInterface $themeFactory, ThemeInterface $theme) |
44
|
|
|
{ |
45
|
|
|
$filesystem->exists('/themes/SampleTheme/theme.json')->willReturn(true); |
46
|
|
|
$filesystem->getFileContents('/themes/SampleTheme/theme.json')->willReturn( |
47
|
|
|
'{ "name": "Sample Theme", "slug": "sylius/sample-theme", "description": "Lorem ipsum dolor sit amet." }' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$themeFactory->createFromArray([ |
51
|
|
|
"name" => "Sample Theme", |
52
|
|
|
"slug" => "sylius/sample-theme", |
53
|
|
|
"description" => "Lorem ipsum dolor sit amet.", |
54
|
|
|
])->willReturn($theme); |
55
|
|
|
|
56
|
|
|
$theme->setPath('/themes/SampleTheme')->shouldBeCalled(); |
57
|
|
|
|
58
|
|
|
$this->load('/themes/SampleTheme/theme.json')->shouldReturn($theme); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function it_throws_exception_if_given_file_does_not_exist(FilesystemInterface $filesystem) |
62
|
|
|
{ |
63
|
|
|
$filesystem->exists('/non/existent/path/60861204')->willReturn(false); |
64
|
|
|
|
65
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringLoad('/non/existent/path/60861204'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|