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
|
|
|
|