Completed
Push — scalar-types/theme ( 71f30c )
by Kamil
21:15
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
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\Templating\Cache\Warmer;
15
16
use Doctrine\Common\Cache\Cache;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException;
19
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
20
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
21
use Sylius\Bundle\ThemeBundle\Templating\Cache\Warmer\TemplatePathsCacheWarmer;
22
use Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateLocatorInterface;
23
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
24
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
25
use Symfony\Component\Templating\TemplateReferenceInterface;
26
27
/**
28
 * @author Kamil Kokot <[email protected]>
29
 */
30
final class TemplatePathsCacheWarmerSpec extends ObjectBehavior
31
{
32
    function let(
33
        TemplateFinderInterface $templateFinder,
34
        TemplateLocatorInterface $templateLocator,
35
        ThemeRepositoryInterface $themeRepository,
36
        Cache $cache
37
    ): void {
38
        $this->beConstructedWith($templateFinder, $templateLocator, $themeRepository, $cache);
39
    }
40
41
    function it_implements_cache_warmer_interface(): void
42
    {
43
        $this->shouldImplement(CacheWarmerInterface::class);
44
    }
45
46
    function it_builds_cache_by_warming_up_every_template_and_every_theme_together(
47
        TemplateFinderInterface $templateFinder,
48
        TemplateLocatorInterface $templateLocator,
49
        ThemeRepositoryInterface $themeRepository,
50
        Cache $cache,
51
        ThemeInterface $theme,
52
        TemplateReferenceInterface $firstTemplate,
53
        TemplateReferenceInterface $secondTemplate
54
    ): void {
55
        $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]);
56
57
        $themeRepository->findAll()->willReturn([$theme]);
58
59
        $theme->getName()->willReturn('theme/name');
60
        $firstTemplate->getLogicalName()->willReturn('Logical:Name:First');
61
        $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second');
62
63
        $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig');
64
        $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class);
65
66
        $cache->save('Logical:Name:First|theme/name', '/First/Theme/index.html.twig')->shouldBeCalled();
67
        $cache->save('Logical:Name:Second|theme/name', null)->shouldBeCalled();
68
69
        $this->warmUp(null);
70
    }
71
}
72