TwigTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 2
A testRender() 0 36 1
A tearDown() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
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
			->willReturn( 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
			->willReturn( array( 'testblock' ) );
53
54
		$view->expects( $this->once() )->method( 'renderBlock' )
55
			->willReturn( 'block content' );
56
57
		$view->expects( $this->once() )->method( 'render' )
58
			->willReturn( '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
			->willReturn( $loader );
67
68
		$this->mock->expects( $this->once() )->method( 'loadTemplate' )
69
			->willReturn( $view );
70
71
72
		$result = $this->object->render( $v, __FILE__, array( 'key' => 'value' ) );
73
		$this->assertEquals( 'test', $result );
74
	}
75
}
76