Completed
Push — master ( 416e0d...8de403 )
by Aimeos
01:52
created
lib/custom/tests/MW/View/Engine/TwigTest.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,56 +16,56 @@
 block discarded – undo
16 16
 
17 17
 	protected function setUp()
18 18
 	{
19
-		if( !class_exists( '\Twig_Environment' ) ) {
20
-			$this->markTestSkipped( 'Twig_Environment is not available' );
19
+		if (!class_exists('\Twig_Environment')) {
20
+			$this->markTestSkipped('Twig_Environment is not available');
21 21
 		}
22 22
 
23
-		$this->mock = $this->getMockBuilder( '\Twig_Environment' )
24
-			->setMethods( array( 'getLoader', 'loadTemplate' ) )
23
+		$this->mock = $this->getMockBuilder('\Twig_Environment')
24
+			->setMethods(array('getLoader', 'loadTemplate'))
25 25
 			->disableOriginalConstructor()
26 26
 			->getMock();
27 27
 
28
-		$this->object = new \Aimeos\MW\View\Engine\Twig( $this->mock );
28
+		$this->object = new \Aimeos\MW\View\Engine\Twig($this->mock);
29 29
 	}
30 30
 
31 31
 
32 32
 	protected function tearDown()
33 33
 	{
34
-		unset( $this->object, $this->mock );
34
+		unset($this->object, $this->mock);
35 35
 	}
36 36
 
37 37
 
38 38
 	public function testRender()
39 39
 	{
40
-		$v = new \Aimeos\MW\View\Standard( array() );
40
+		$v = new \Aimeos\MW\View\Standard(array());
41 41
 
42
-		$view = $this->getMockBuilder( '\Twig_Template' )
43
-			->setConstructorArgs( array ( $this->mock ) )
44
-			->setMethods( array( 'getBlockNames', 'render', 'renderBlock' ) )
42
+		$view = $this->getMockBuilder('\Twig_Template')
43
+			->setConstructorArgs(array($this->mock))
44
+			->setMethods(array('getBlockNames', 'render', 'renderBlock'))
45 45
 			->getMockForAbstractClass();
46 46
 
47
-		$view->expects( $this->once() )->method( 'getBlockNames' )
48
-			->will( $this->returnValue( array( 'testblock' ) ) );
47
+		$view->expects($this->once())->method('getBlockNames')
48
+			->will($this->returnValue(array('testblock')));
49 49
 
50
-		$view->expects( $this->once() )->method( 'renderBlock' )
51
-			->will( $this->returnValue( 'block content' ) );
50
+		$view->expects($this->once())->method('renderBlock')
51
+			->will($this->returnValue('block content'));
52 52
 
53
-		$view->expects( $this->once() )->method( 'render' )
54
-			->will( $this->returnValue( 'test' ) );
53
+		$view->expects($this->once())->method('render')
54
+			->will($this->returnValue('test'));
55 55
 
56 56
 
57
-		$loader = $this->getMockBuilder( '\Twig_LoaderInterface' )
57
+		$loader = $this->getMockBuilder('\Twig_LoaderInterface')
58 58
 			->disableOriginalConstructor()
59 59
 			->getMockForAbstractClass();
60 60
 
61
-		$this->mock->expects( $this->once() )->method( 'getLoader' )
62
-			->will( $this->returnValue( $loader) );
61
+		$this->mock->expects($this->once())->method('getLoader')
62
+			->will($this->returnValue($loader));
63 63
 
64
-		$this->mock->expects( $this->once() )->method( 'loadTemplate' )
65
-			->will( $this->returnValue( $view) );
64
+		$this->mock->expects($this->once())->method('loadTemplate')
65
+			->will($this->returnValue($view));
66 66
 
67 67
 
68
-		$result = $this->object->render( $v, __FILE__, array( 'key' => 'value' ) );
69
-		$this->assertEquals( 'test', $result );
68
+		$result = $this->object->render($v, __FILE__, array('key' => 'value'));
69
+		$this->assertEquals('test', $result);
70 70
 	}
71 71
 }
Please login to merge, or discard this patch.
lib/custom/src/MW/View/Engine/Twig.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 *
28 28
 	 * @param \Twig_Environment $env Twig environment object
29 29
 	 */
30
-	public function __construct( \Twig_Environment $env )
30
+	public function __construct(\Twig_Environment $env)
31 31
 	{
32 32
 		$this->env = $env;
33 33
 	}
@@ -42,33 +42,33 @@  discard block
 block discarded – undo
42 42
 	 * @return string Output generated by the template
43 43
 	 * @throws \Aimeos\MW\View\Exception If the template isn't found
44 44
 	 */
45
-	public function render( \Aimeos\MW\View\Iface $view, $filename, array $values )
45
+	public function render(\Aimeos\MW\View\Iface $view, $filename, array $values)
46 46
 	{
47 47
 		$loader = $this->env->getLoader();
48 48
 
49
-		if( ( $content = @file_get_contents( $filename ) ) === false ) {
50
-			throw new \Aimeos\MW\View\Exception( sprintf( 'Template "%1$s" not found', $filename ) );
49
+		if (($content = @file_get_contents($filename)) === false) {
50
+			throw new \Aimeos\MW\View\Exception(sprintf('Template "%1$s" not found', $filename));
51 51
 		}
52 52
 
53
-		$custom = new \Twig_Loader_Array( array( $filename => $content ) );
54
-		$this->env->setLoader( new \Twig_Loader_Chain( array( $custom, $loader ) ) );
53
+		$custom = new \Twig_Loader_Array(array($filename => $content));
54
+		$this->env->setLoader(new \Twig_Loader_Chain(array($custom, $loader)));
55 55
 
56 56
 		try
57 57
 		{
58
-			$template = $this->env->loadTemplate( $filename );
59
-			$content = $template->render( $values );
58
+			$template = $this->env->loadTemplate($filename);
59
+			$content = $template->render($values);
60 60
 
61
-			foreach( $template->getBlockNames( $values ) as $key ) {
62
-				$view->block()->set( $key, $template->renderBlock( $key, $values ) );
61
+			foreach ($template->getBlockNames($values) as $key) {
62
+				$view->block()->set($key, $template->renderBlock($key, $values));
63 63
 			}
64 64
 
65
-			$this->env->setLoader( $loader );
65
+			$this->env->setLoader($loader);
66 66
 
67 67
 			return $content;
68 68
 		}
69
-		catch( \Exception $e )
69
+		catch (\Exception $e)
70 70
 		{
71
-			$this->env->setLoader( $loader );
71
+			$this->env->setLoader($loader);
72 72
 			throw $e;
73 73
 		}
74 74
 	}
Please login to merge, or discard this patch.