Completed
Push — theme-bundle ( aad440...af4cdd )
by Kamil
15:45
created

TemplatePathsCacheWarmerSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 8 1
A it_is_initializable() 0 4 1
A it_implements_cache_warmer_interface() 0 4 1
B it_builds_cache_by_warming_up_every_template_and_every_theme_together() 0 25 1
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\Templating\Cache\Warmer;
13
14
use Doctrine\Common\Cache\Cache;
15
use PhpSpec\ObjectBehavior;
16
use Prophecy\Argument;
17
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException;
18
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
19
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
20
use Sylius\Bundle\ThemeBundle\Templating\Cache\Warmer\TemplatePathsCacheWarmer;
21
use Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateLocatorInterface;
22
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
23
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
24
use Symfony\Component\Templating\TemplateReferenceInterface;
25
26
/**
27
 * @mixin TemplatePathsCacheWarmer
28
 *
29
 * @author Kamil Kokot <[email protected]>
30
 */
31
class TemplatePathsCacheWarmerSpec extends ObjectBehavior
32
{
33
    function let(
34
        TemplateFinderInterface $templateFinder,
35
        TemplateLocatorInterface $templateLocator,
36
        ThemeRepositoryInterface $themeRepository,
37
        Cache $cache
38
    ) {
39
        $this->beConstructedWith($templateFinder, $templateLocator, $themeRepository, $cache);
40
    }
41
42
    function it_is_initializable()
43
    {
44
        $this->shouldHaveType('Sylius\Bundle\ThemeBundle\Templating\Cache\Warmer\TemplatePathsCacheWarmer');
45
    }
46
47
    function it_implements_cache_warmer_interface()
48
    {
49
        $this->shouldImplement(CacheWarmerInterface::class);
50
    }
51
52
    function it_builds_cache_by_warming_up_every_template_and_every_theme_together(
53
        TemplateFinderInterface $templateFinder,
54
        TemplateLocatorInterface $templateLocator,
55
        ThemeRepositoryInterface $themeRepository,
56
        Cache $cache,
57
        ThemeInterface $theme,
58
        TemplateReferenceInterface $firstTemplate,
59
        TemplateReferenceInterface $secondTemplate
60
    ) {
61
        $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]);
62
63
        $themeRepository->findAll()->willReturn([$theme]);
64
65
        $theme->getSlug()->willReturn('theme/slug');
66
        $firstTemplate->getLogicalName()->willReturn('Logical:Name:First');
67
        $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second');
68
69
        $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig');
70
        $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class);
71
72
        $cache->save('Logical:Name:First|theme/slug', '/First/Theme/index.html.twig')->shouldBeCalled();
73
        $cache->save('Logical:Name:Second|theme/slug', null)->shouldBeCalled();
74
75
        $this->warmUp(null);
76
    }
77
}
78