[TASK] Add CompilableInterface to a couple of view helpers 86/36286/7
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 26 Jan 2015 23:03:45 +0000 (00:03 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 28 Jan 2015 16:33:26 +0000 (17:33 +0100)
This patch changes a couple of view helpers that can easily
implement CompilableInterface to supress object creating at
render time.

TranslateViewHelper is especially interesting since this
one is used very often.

CommentViewHelper additionally overwrites compile() so
child nodes (the comments) are not evaluated at all.

All these view helpers are used in be_user access module
and lead to a speed up from roughly 7 to 5 seconds for
a list of 900 pages on my testsystem, now creating "only"
14 thousand objects instead of 21 thousand.

Change-Id: Ic1f90cb1d1ec013181b26d9274d097ed0a01d08e
Resolves: #64546
Releases: master
Reviewed-on: http://review.typo3.org/36286
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/beuser/Classes/ViewHelpers/ArrayElementViewHelper.php
typo3/sysext/beuser/Classes/ViewHelpers/SpriteManagerIconViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/CommentViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/ElseViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/RawViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/ThenViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/TranslateViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ElseViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/RawViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ThenViewHelperTest.php

index abf89be..89fec24 100644 (file)
@@ -14,21 +14,40 @@ namespace TYPO3\CMS\Beuser\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Get a value from an array by given key.
  */
-class ArrayElementViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class ArrayElementViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
-        * Return array element by key. Acessed values must be scalar (string, int, float or double)
+        * Return array element by key. Accessed values must be scalar (string, int, float or double)
         *
         * @param array $array Array to search in
         * @param string $key Key to return its value
         * @param string $subKey If result of key access is an array, subkey can be used to fetch an element from this again
-        * @throws \TYPO3\CMS\Beuser\Exception
         * @return string
         */
        public function render(array $array, $key, $subKey = '') {
+               return self::renderStatic(array('array' => $array, 'key' => $key, 'subKey' => $subKey), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Return array element by key.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @throws \TYPO3\CMS\Beuser\Exception
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $array = $arguments['array'];
+               $key = $arguments['key'];
+               $subKey = $arguments['subKey'];
                $result = '';
                if (is_array($array) && isset($array[$key])) {
                        $result = $array[$key];
index e2042b5..ee7f293 100644 (file)
@@ -14,13 +14,18 @@ namespace TYPO3\CMS\Beuser\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Displays sprite icon identified by iconName key
  *
  * @author Felix Kopp <felix-source@phorax.com>
  * @internal
  */
-class SpriteManagerIconViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
+class SpriteManagerIconViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Prints sprite icon html for $iconName key
@@ -30,7 +35,21 @@ class SpriteManagerIconViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\Abstra
         * @return string
         */
        public function render($iconName, $options = array()) {
-               return \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon($iconName, $options);
+               return self::renderStatic(array('iconName' => $iconName, 'options' => $options), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Print sprite icon html for $iconName key
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $iconName = $arguments['iconName'];
+               $options = $arguments['options'];
+               return IconUtility::getSpriteIcon($iconName, $options);
        }
 
 }
index 40054ca..dbab00e 100644 (file)
@@ -11,6 +11,12 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode;
+use TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler;
+
 /**
  * This ViewHelper prevents rendering of any content inside the tag
  * Note: Contents of the comment will still be **parsed** thus throwing an
@@ -42,7 +48,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  *
  * @api
  */
-class CommentViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class CommentViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * @var bool
@@ -58,4 +64,30 @@ class CommentViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
        public function render() {
        }
 
+       /**
+        * Does not render children
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               return '';
+       }
+
+       /**
+        * The inner contents of a comment should not be rendered.
+        *
+        * @param string $argumentsVariableName
+        * @param string $renderChildrenClosureVariableName
+        * @param string $initializationPhpCode
+        * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode
+        * @param \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
+        * @return string
+        */
+       public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, AbstractNode $syntaxTreeNode, TemplateCompiler $templateCompiler) {
+               return '\'\'';
+       }
+
 }
index 66d3916..b45b8df 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Else-Branch of a condition. Only has an effect inside of "If". See the If-ViewHelper for documentation.
  *
@@ -31,14 +35,26 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * @see TYPO3\CMS\Fluid\ViewHelpers\IfViewHelper
  * @api
  */
-class ElseViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class ElseViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * @return string the rendered string
         * @api
         */
        public function render() {
-               return $this->renderChildren();
+               return self::renderStatic(array(), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Render children
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               return $renderChildrenClosure();
        }
 
 }
index ea78a94..4c44a52 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Outputs an argument/value without any escaping. Is normally used to output
  * an ObjectAccessor which should not be escaped, but output as-is.
@@ -43,7 +47,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class RawViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class RawViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -58,8 +62,21 @@ class RawViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
         * @return string
         */
        public function render($value = NULL) {
+               return self::renderStatic(array('value' => $value), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Render children without escaping
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
                if ($value === NULL) {
-                       return $this->renderChildren();
+                       return $renderChildrenClosure();
                } else {
                        return $value;
                }
index dc06966..0d2b7b1 100644 (file)
@@ -11,13 +11,17 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * "THEN" -> only has an effect inside of "IF". See If-ViewHelper for documentation.
  *
  * @see \TYPO3\CMS\Fluid\ViewHelpers\IfViewHelper
  * @api
  */
-class ThenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class ThenViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Just render everything.
@@ -26,7 +30,19 @@ class ThenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
         * @api
         */
        public function render() {
-               return $this->renderChildren();
+               return self::renderStatic(array(), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Render children
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               return $renderChildrenClosure();
        }
 
 }
index fc4966c..02b5699 100644 (file)
@@ -13,6 +13,12 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
  * Public License for more details.                                       *
  *                                                                        */
+
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Translate a key from locallang. The files are loaded from the folder
  * "Resources/Private/Language/".
@@ -64,55 +70,69 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * value of id "key1" in the current website language
  * </output>
  */
-class TranslateViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class TranslateViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
-        * Initializes arguments for Translate ViewHelper
+        * Render translation
         *
-        * @return void
+        * @param string $key Translation Key
+        * @param string $id Translation Key compatible to TYPO3 Flow
+        * @param string $default If the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default
+        * @param bool $htmlEscape TRUE if the result should be htmlescaped. This won't have an effect for the default value
+        * @param array $arguments Arguments to be replaced in the resulting string
+        * @param string $extensionName UpperCamelCased extension key (for example BlogExample)
+        * @return string The translated key or tag body if key doesn't exist
         */
-       public function initializeArguments() {
-               $this->registerArgument('key', 'string', 'Translation Key');
-               $this->registerArgument('id', 'string', 'Translation Key compatible to TYPO3 Flow');
-               $this->registerArgument('default', 'string', 'if the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default');
-               $this->registerArgument('htmlEscape', 'boolean', 'TRUE if the result should be htmlescaped. This won\'t have an effect for the default value');
-               $this->registerArgument('arguments', 'array', 'Arguments to be replaced in the resulting string');
-               $this->registerArgument('extensionName', 'string', 'UpperCamelCased extension key (for example BlogExample)');
+       public function render($key = NULL, $id = NULL, $default = NULL, $htmlEscape = NULL, array $arguments = array(), $extensionName = NULL) {
+               return self::renderStatic(
+                       array(
+                               'key' => $key,
+                               'id' => $id,
+                               'default' => $default,
+                               'htmlEscape' => $htmlEscape,
+                               'arguments' => $arguments,
+                               'extensionName' => $extensionName,
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
        }
 
        /**
-        * Wrapper function including a compatibility layer for TYPO3 Flow Translation
+        * Return array element by key.
         *
-        * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
-        *
-        * @return string The translated key or tag body if key doesn't exist
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @throws InvalidVariableException
+        * @return string
         */
-       public function render() {
-               $id = $this->hasArgument('id') ? $this->arguments['id'] : $this->arguments['key'];
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $key = $arguments['key'];
+               $id = $arguments['id'];
+               $default = $arguments['default'];
+               $htmlEscape = $arguments['htmlEscape'];
+               $extensionName = $arguments['extensionName'];
+               $arguments = $arguments['arguments'];
 
-               if ((string)$id !== '') {
-                       return $this->renderTranslation($id);
-               } else {
-                       throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('An argument "key" or "id" has to be provided', 1351584844);
+               // Wrapper including a compatibility layer for TYPO3 Flow Translation
+               if ($id === NULL) {
+                       $id = $key;
                }
-       }
 
-       /**
-        * Translate a given key or use the tag body as default.
-        *
-        * @param string $id The locallang id
-        * @return string The translated key or tag body if key doesn't exist
-        */
-       protected function renderTranslation($id) {
-               $request = $this->controllerContext->getRequest();
-               $extensionName = $this->arguments['extensionName'] === NULL ? $request->getControllerExtensionName() : $this->arguments['extensionName'];
-               $value = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($id, $extensionName, $this->arguments['arguments']);
+               if ((string)$id === '') {
+                       throw new InvalidVariableException('An argument "key" or "id" has to be provided', 1351584844);
+               }
+
+               $request = $renderingContext->getControllerContext()->getRequest();
+               $extensionName = $extensionName === NULL ? $request->getControllerExtensionName() : $extensionName;
+               $value = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($id, $extensionName, $arguments);
                if ($value === NULL) {
-                       $value = $this->arguments['default'] !== NULL ? $this->arguments['default'] : $this->renderChildren();
-                       if (is_array($this->arguments['arguments'])) {
-                               $value = vsprintf($value, $this->arguments['arguments']);
+                       $value = $default !== NULL ? $default : $renderChildrenClosure();
+                       if (!empty($arguments)) {
+                               $value = vsprintf($value, $arguments);
                        }
-               } elseif ($this->arguments['htmlEscape']) {
+               } elseif ($htmlEscape) {
                        $value = htmlspecialchars($value);
                }
                return $value;
index 8416ed3..2442356 100644 (file)
@@ -11,19 +11,30 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\ViewHelpers\ElseViewHelper;
+
 /**
- * Testcase for ElseViewHelper
+ * Test case
  */
-class ElseViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
+class ElseViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var ElseViewHelper|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $subject;
+
+       public function setUp() {
+               parent::setUp();
+               $this->subject = $this->getMock(ElseViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->subject);
+       }
 
        /**
         * @test
         */
        public function renderRendersChildren() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\ElseViewHelper::class, array('renderChildren'));
-
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
-               $actualResult = $viewHelper->render();
+               $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
+               $actualResult = $this->subject->render();
                $this->assertEquals('foo', $actualResult);
        }
 
index c59537a..7057d40 100644 (file)
@@ -11,25 +11,30 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+use TYPO3\CMS\Fluid\ViewHelpers\Format\RawViewHelper;
+
 /**
  * Test case
  */
-class RawViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class RawViewHelperTest extends ViewHelperBaseTestcase {
 
        /**
-        * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\RawViewHelper
+        * @var RawViewHelper|\PHPUnit_Framework_MockObject_MockObject
         */
-       protected $viewHelper;
+       protected $subject;
 
        public function setUp() {
-               $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\RawViewHelper::class, array('renderChildren'));
+               parent::setUp();
+               $this->subject = $this->getMock(RawViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->subject);
        }
 
        /**
         * @test
         */
        public function viewHelperDeactivatesEscapingInterceptor() {
-               $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
+               $this->assertFalse($this->subject->isEscapingInterceptorEnabled());
        }
 
        /**
@@ -37,8 +42,8 @@ class RawViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function renderReturnsUnmodifiedValueIfSpecified() {
                $value = 'input value " & äöüß@';
-               $this->viewHelper->expects($this->never())->method('renderChildren');
-               $actualResult = $this->viewHelper->render($value);
+               $this->subject->expects($this->never())->method('renderChildren');
+               $actualResult = $this->subject->render($value);
                $this->assertEquals($value, $actualResult);
        }
 
@@ -47,8 +52,8 @@ class RawViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function renderReturnsUnmodifiedChildNodesIfNoValueIsSpecified() {
                $childNodes = 'input value " & äöüß@';
-               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($childNodes));
-               $actualResult = $this->viewHelper->render();
+               $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue($childNodes));
+               $actualResult = $this->subject->render();
                $this->assertEquals($childNodes, $actualResult);
        }
 
index b00af83..4dd7f7f 100644 (file)
@@ -11,19 +11,30 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\ViewHelpers\ThenViewHelper;
+
 /**
- * Testcase for ElseViewHelper
+ * Test case
  */
-class ThenViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
+class ThenViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var ThenViewHelper|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $subject;
+
+       public function setUp() {
+               parent::setUp();
+               $this->subject = $this->getMock(ThenViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->subject);
+       }
 
        /**
         * @test
         */
        public function renderRendersChildren() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\ThenViewHelper::class, array('renderChildren'));
-
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
-               $actualResult = $viewHelper->render();
+               $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
+               $actualResult = $this->subject->render();
                $this->assertEquals('foo', $actualResult);
        }