summaryrefslogtreecommitdiffstats
path: root/tests/Controller/View/TwigTest.php
blob: 566787ff474eb82b982db90bb1df57f9e4c178b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Jasny\Controller\View;

use Jasny\Controller\View;
use Jasny\View\Twig as TwigView;
use Jasny\Controller\TestHelper;

/**
 * @covers Jasny\Controller\View\Twig
 */
class TwigTest extends \PHPUnit_Framework_TestCase
{
    use TestHelper {
        getController as private _getController;
    }

    /**
     * @return string
     */
    protected function getControllerClass()
    {
        return View\Twig::class;
    }
    
    /**
     * Get mock controller
     * 
     * @param array  $methods
     * @param string $className
     * @return RouteActionController|\PHPUnit_Framework_MockObject_MockObject
     */
    protected function getController($methods = [], $className = null)
    {
        $controller = $this->_getController(array_merge($methods, ['createTwigView', 'getViewPath']), $className);
        $controller->method('getViewPath')->willReturn('/tmp');
        
        return $controller;
    }

    
    public function testGetViewer()
    {
        $viewer = $this->createMock(TwigView::class);
        $viewer->expects($this->once())->method('addDefaultExtensions');
        
        $controller = $this->getController();
        $controller->method('createTwigView')->willReturn($viewer);
        
        $this->assertSame($viewer, $controller->getViewer());
        
        // Idempotent
        $this->assertSame($viewer, $controller->getViewer());
    }
}