Completed
Push — master ( 4e1c5d...6050c4 )
by Grégoire
22:25 queued 19:06
created

TemplateRegistryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 67
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetTemplates() 0 13 1
A testSetTemplate() 0 12 1
A testSetTemplates() 0 17 1
A testThrowExceptionIfTheTemplateDoesNotExist() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Templating;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Templating\TemplateRegistry;
18
19
class TemplateRegistryTest extends TestCase
20
{
21
    /**
22
     * @var TemplateRegistry
23
     */
24
    private $templateRegistry;
25
26
    protected function setUp(): void
27
    {
28
        $this->templateRegistry = new TemplateRegistry();
29
    }
30
31
    public function testGetTemplates(): void
32
    {
33
        $this->assertSame([], $this->templateRegistry->getTemplates());
34
35
        $templates = [
36
            'list' => '@FooAdmin/CRUD/list.html.twig',
37
            'show' => '@FooAdmin/CRUD/show.html.twig',
38
            'edit' => '@FooAdmin/CRUD/edit.html.twig',
39
        ];
40
41
        $this->templateRegistry->setTemplates($templates);
42
        $this->assertSame($templates, $this->templateRegistry->getTemplates());
43
    }
44
45
    public function testSetTemplate(): void
46
    {
47
        $this->assertFalse($this->templateRegistry->hasTemplate('edit'));
48
49
        $this->templateRegistry->setTemplate('edit', '@FooAdmin/CRUD/edit.html.twig');
50
        $this->templateRegistry->setTemplate('show', '@FooAdmin/CRUD/show.html.twig');
51
52
        $this->assertTrue($this->templateRegistry->hasTemplate('edit'));
53
        $this->assertSame('@FooAdmin/CRUD/edit.html.twig', $this->templateRegistry->getTemplate('edit'));
54
        $this->assertTrue($this->templateRegistry->hasTemplate('show'));
55
        $this->assertSame('@FooAdmin/CRUD/show.html.twig', $this->templateRegistry->getTemplate('show'));
56
    }
57
58
    public function testSetTemplates(): void
59
    {
60
        $this->assertFalse($this->templateRegistry->hasTemplate('edit'));
61
62
        $templates = [
63
            'list' => '@FooAdmin/CRUD/list.html.twig',
64
            'show' => '@FooAdmin/CRUD/show.html.twig',
65
            'edit' => '@FooAdmin/CRUD/edit.html.twig',
66
        ];
67
68
        $this->templateRegistry->setTemplates($templates);
69
70
        $this->assertTrue($this->templateRegistry->hasTemplate('edit'));
71
        $this->assertSame('@FooAdmin/CRUD/edit.html.twig', $this->templateRegistry->getTemplate('edit'));
72
        $this->assertTrue($this->templateRegistry->hasTemplate('show'));
73
        $this->assertSame('@FooAdmin/CRUD/show.html.twig', $this->templateRegistry->getTemplate('show'));
74
    }
75
76
    public function testThrowExceptionIfTheTemplateDoesNotExist(): void
77
    {
78
        $this->expectException(\InvalidArgumentException::class);
79
        $this->expectExceptionMessage('Template named "edit" doesn\'t exist.');
80
81
        $this->assertFalse($this->templateRegistry->hasTemplate('edit'));
82
83
        $this->templateRegistry->getTemplate('edit');
84
    }
85
}
86