Completed
Push — master ( b952ca...416e0d )
by Aimeos
01:59
created
lib/custom/tests/MW/View/Engine/TwigTest.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,53 +16,53 @@
 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( 'getBlocks', 'render' ) )
42
+		$view = $this->getMockBuilder('\Twig_Template')
43
+			->setConstructorArgs(array($this->mock))
44
+			->setMethods(array('getBlocks', 'render'))
45 45
 			->getMockForAbstractClass();
46 46
 
47
-		$view->expects( $this->once() )->method( 'getBlocks' )
48
-			->will( $this->returnValue( array( 'test', 'content' ) ) );
47
+		$view->expects($this->once())->method('getBlocks')
48
+			->will($this->returnValue(array('test', 'content')));
49 49
 
50
-		$view->expects( $this->once() )->method( 'render' )
51
-			->will( $this->returnValue( 'test' ) );
50
+		$view->expects($this->once())->method('render')
51
+			->will($this->returnValue('test'));
52 52
 
53 53
 
54
-		$loader = $this->getMockBuilder( '\Twig_LoaderInterface' )
54
+		$loader = $this->getMockBuilder('\Twig_LoaderInterface')
55 55
 			->disableOriginalConstructor()
56 56
 			->getMockForAbstractClass();
57 57
 
58
-		$this->mock->expects( $this->once() )->method( 'getLoader' )
59
-			->will( $this->returnValue( $loader) );
58
+		$this->mock->expects($this->once())->method('getLoader')
59
+			->will($this->returnValue($loader));
60 60
 
61
-		$this->mock->expects( $this->once() )->method( 'loadTemplate' )
62
-			->will( $this->returnValue( $view) );
61
+		$this->mock->expects($this->once())->method('loadTemplate')
62
+			->will($this->returnValue($view));
63 63
 
64 64
 
65
-		$result = $this->object->render( $v, __FILE__, array( 'key' => 'value' ) );
66
-		$this->assertEquals( 'test', $result );
65
+		$result = $this->object->render($v, __FILE__, array('key' => 'value'));
66
+		$this->assertEquals('test', $result);
67 67
 	}
68 68
 }
Please login to merge, or discard this patch.
lib/custom/src/MW/View/Engine/Twig.php 2 patches
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->getBlocks() as $key => $block ) {
62
-				$view->block()->set( $key, $block );
61
+			foreach ($template->getBlocks() as $key => $block) {
62
+				$view->block()->set($key, $block);
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.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@
 block discarded – undo
65 65
 			$this->env->setLoader( $loader );
66 66
 
67 67
 			return $content;
68
-		}
69
-		catch( \Exception $e )
68
+		} catch( \Exception $e )
70 69
 		{
71 70
 			$this->env->setLoader( $loader );
72 71
 			throw $e;
Please login to merge, or discard this patch.