Passed
Push — master ( ad651e...cb72cb )
by Aimeos
12:16
created

TwigTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2023
6
 */
7
8
namespace Aimeos\Base\View\Engine;
9
10
11
class TwigTest extends \PHPUnit\Framework\TestCase
12
{
13
	private $object;
14
	private $mock;
15
16
17
	protected function setUp() : void
18
	{
19
		if( !class_exists( '\Twig\Environment' ) ) {
20
			$this->markTestSkipped( 'Twig\Environment is not available' );
21
		}
22
23
		$this->mock = $this->getMockBuilder( '\Twig\Environment' )
24
			->onlyMethods( array( 'getExtensions', 'getLoader', 'loadTemplate' ) )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$this->object = new \Aimeos\Base\View\Engine\Twig( $this->mock );
29
	}
30
31
32
	protected function tearDown() : void
33
	{
34
		unset( $this->object, $this->mock );
35
	}
36
37
38
	public function testRender()
39
	{
40
		$v = new \Aimeos\Base\View\Standard( [] );
41
42
		$this->mock->expects( $this->any() )->method( 'getExtensions' )
43
			->will( $this->returnValue( array( [] ) ) );
44
45
46
		$view = $this->getMockBuilder( '\Twig\Template' )
47
			->setConstructorArgs( array( $this->mock ) )
48
			->onlyMethods( array( 'getBlockNames', 'render', 'renderBlock' ) )
49
			->getMockForAbstractClass();
50
51
		$view->expects( $this->once() )->method( 'getBlockNames' )
52
			->will( $this->returnValue( array( 'testblock' ) ) );
53
54
		$view->expects( $this->once() )->method( 'renderBlock' )
55
			->will( $this->returnValue( 'block content' ) );
56
57
		$view->expects( $this->once() )->method( 'render' )
58
			->will( $this->returnValue( 'test' ) );
59
60
61
		$loader = $this->getMockBuilder( '\Twig\Loader\LoaderInterface' )
62
			->disableOriginalConstructor()
63
			->getMockForAbstractClass();
64
65
		$this->mock->expects( $this->exactly( 2 ) )->method( 'getLoader' )
66
			->will( $this->returnValue( $loader ) );
67
68
		$this->mock->expects( $this->once() )->method( 'loadTemplate' )
69
			->will( $this->returnValue( $view ) );
70
71
72
		$result = $this->object->render( $v, __FILE__, array( 'key' => 'value' ) );
73
		$this->assertEquals( 'test', $result );
74
	}
75
}
76