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

TemplateNameParserSpec::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
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Sylius\Bundle\ThemeBundle\Templating;
6
7
use PhpSpec\ObjectBehavior;
8
use Sylius\Bundle\ThemeBundle\Templating\TemplateNameParser;
9
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
10
use Symfony\Component\HttpKernel\KernelInterface;
11
use Symfony\Component\Templating\TemplateNameParserInterface;
12
use Symfony\Component\Templating\TemplateReferenceInterface;
13
14
/**
15
 * @author Kamil Kokot <[email protected]>
16
 */
17
final class TemplateNameParserSpec extends ObjectBehavior
18
{
19
    function let(TemplateNameParserInterface $decoratedParser, KernelInterface $kernel): void
20
    {
21
        $this->beConstructedWith($decoratedParser, $kernel);
22
    }
23
24
    function it_is_a_template_name_parser(): void
25
    {
26
        $this->shouldImplement(TemplateNameParserInterface::class);
27
    }
28
29
    function it_returns_template_reference_if_passed_as_name(TemplateReferenceInterface $templateReference): void
30
    {
31
        $this->parse($templateReference)->shouldReturn($templateReference);
32
    }
33
34
    function it_delegates_logical_paths_to_decorated_parser(
35
        TemplateNameParserInterface $decoratedParser,
36
        TemplateReferenceInterface $templateReference
37
    ): void {
38
        $decoratedParser->parse('Bundle:Not:namespaced.html.twig')->willReturn($templateReference);
39
40
        $this->parse('Bundle:Not:namespaced.html.twig')->shouldReturn($templateReference);
41
    }
42
43
    function it_delegates_unknown_paths_to_decorated_parser(
44
        TemplateNameParserInterface $decoratedParser,
45
        TemplateReferenceInterface $templateReference
46
    ): void {
47
        $decoratedParser->parse('Bundle/Not/namespaced.html.twig')->willReturn($templateReference);
48
49
        $this->parse('Bundle/Not/namespaced.html.twig')->shouldReturn($templateReference);
50
    }
51
52
    function it_generates_template_references_from_namespaced_paths(KernelInterface $kernel): void
53
    {
54
        $kernel->getBundle('AcmeBundle')->willReturn(null); // just do not throw an exception
55
56
        $this->parse('@Acme/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', '', 'app', 'html', 'twig'));
57
        $this->parse('@Acme/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory', 'app', 'html', 'twig'));
58
        $this->parse('@Acme/Directory.WithDot/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory.WithDot', 'app', 'html', 'twig'));
59
        $this->parse('@Acme/Directory/app.with.dots.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory', 'app.with.dots', 'html', 'twig'));
60
        $this->parse('@Acme/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Nested/Directory', 'app', 'html', 'twig'));
61
    }
62
63
    function it_delegates_custom_namespace_to_decorated_parser(
64
        KernelInterface $kernel,
65
        TemplateNameParserInterface $decoratedParser,
66
        TemplateReferenceInterface $templateReference
67
    ): void {
68
        $kernel->getBundle('myBundle')->willThrow(\Exception::class);
69
70
        $decoratedParser->parse('@my/custom/namespace.html.twig')->willReturn($templateReference);
71
72
        $this->parse('@my/custom/namespace.html.twig')->shouldReturn($templateReference);
73
    }
74
75
    function it_generates_template_references_from_root_namespaced_paths(): void
76
    {
77
        $this->parse('/app.html.twig')->shouldBeLike(new TemplateReference('', '', 'app', 'html', 'twig'));
78
        $this->parse('/Directory/app.html.twig')->shouldBeLike(new TemplateReference('', 'Directory', 'app', 'html', 'twig'));
79
        $this->parse('/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('', 'Nested/Directory', 'app', 'html', 'twig'));
80
        $this->parse('/Directory.WithDot/app.html.twig')->shouldBeLike(new TemplateReference('', 'Directory.WithDot', 'app', 'html', 'twig'));
81
    }
82
}
83