Completed
Push — ezp25940-improve_no_view_templ... ( b6d476 )
by
unknown
40:03 queued 18:20
created

TemplateRendererTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testRender() 0 23 1
A testRenderNoViewTemplate() 0 4 1
A createView() 0 5 1
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\MVC\Symfony\View\Tests\Renderer;
7
8
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
9
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
10
use eZ\Publish\Core\MVC\Symfony\View\Renderer\TemplateRenderer;
11
use PHPUnit_Framework_TestCase;
12
13
class TemplateRendererTest extends PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var \eZ\Publish\Core\MVC\Symfony\View\Renderer\TemplateRenderer
17
     */
18
    private $renderer;
19
20
    /**
21
     * @var \Symfony\Component\Templating\EngineInterface|\PHPUnit_Framework_MockObject_MockObject
22
     */
23
    private $templateEngineMock;
24
25
    /**
26
     * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
27
     */
28
    private $eventDispatcherMock;
29
30
    public function setUp()
31
    {
32
        $this->templateEngineMock = $this->getMock('Symfony\Component\Templating\EngineInterface');
33
        $this->eventDispatcherMock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
34
        $this->renderer = new TemplateRenderer(
35
            $this->templateEngineMock,
36
            $this->eventDispatcherMock
37
        );
38
    }
39
    public function testRender()
40
    {
41
        $view = $this->createView();
42
        $view->setTemplateIdentifier('path/to/template.html.twig');
43
44
        $this->eventDispatcherMock
45
            ->expects($this->once())
46
            ->method('dispatch')
47
            ->with(
48
                MVCEvents::PRE_CONTENT_VIEW,
49
                $this->isInstanceOf('\eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent')
50
            );
51
52
        $this->templateEngineMock
53
            ->expects($this->once())
54
            ->method('render')
55
            ->with(
56
                'path/to/template.html.twig',
57
                $view->getParameters()
58
            );
59
60
        $this->renderer->render($view);
61
    }
62
63
    /**
64
     * @expectedException \eZ\Publish\Core\MVC\Exception\NoViewTemplateException
65
     */
66
    public function testRenderNoViewTemplate()
67
    {
68
        $this->renderer->render($this->createView());
69
    }
70
71
    /**
72
     * @return \eZ\Publish\Core\MVC\Symfony\View\View
73
     */
74
    protected function createView()
75
    {
76
        $view = new ContentView();
77
        return $view;
78
    }
79
}
80