[TASK] Replace @expectedException annotation in ext:fluid 65/48465/5
authorNadir Sunar <dernadir@gmail.com>
Mon, 6 Jun 2016 16:46:42 +0000 (18:46 +0200)
committerJan Helke <typo3@helke.de>
Tue, 7 Jun 2016 08:54:04 +0000 (10:54 +0200)
Use expectException() instead of @expectedException in unit
tests and add expectedExceptionCode() where possible.
This patch handles occurences in ext:fluid.

Releases: master
Resolves: #76474
Change-Id: Ie4a9a2c644f34e2b2bd9a1c48dcff60ac56d8194
Reviewed-on: https://review.typo3.org/48465
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/fluid/Tests/Unit/Core/ViewHelper/AbstractViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/Core/Widget/AjaxWidgetContextHolderTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SelectViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/CaseViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/TranslateViewHelperTest.php

index 91d028c..f48d233 100644 (file)
@@ -188,7 +188,6 @@ class AbstractViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
      */
     public function registeringTheSameArgumentNameAgainThrowsException()
     {
@@ -199,6 +198,9 @@ class AbstractViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $type = 'string';
         $isRequired = true;
 
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
+        $this->expectExceptionCode(1253036401);
+
         $viewHelper->_call('registerArgument', $name, $type, $description, $isRequired);
         $viewHelper->_call('registerArgument', $name, 'integer', $description, $isRequired);
     }
@@ -226,13 +228,15 @@ class AbstractViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
      */
     public function overrideArgumentThrowsExceptionWhenTryingToOverwriteAnNonexistingArgument()
     {
         $viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, array('render'), array(), '', false);
         $viewHelper->injectReflectionService($this->mockReflectionService);
 
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
+        $this->expectExceptionCode(1279212461);
+
         $viewHelper->_call('overrideArgument', 'argumentName', 'string', 'description', true);
     }
 
@@ -317,13 +321,15 @@ class AbstractViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \InvalidArgumentException
      */
     public function validateArgumentsCallsTheRightValidatorsAndThrowsExceptionIfValidationIsWrong()
     {
         $viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, array('render', 'prepareArguments'), array(), '', false);
         $viewHelper->injectReflectionService($this->mockReflectionService);
 
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionCode(1256475113);
+
         $viewHelper->setArguments(array('test' => 'test'));
 
         $viewHelper->expects($this->once())->method('prepareArguments')->will($this->returnValue(array(
index 8a1247c..a38e3ba 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget;
  * The TYPO3 project - inspiring people to share!
  */
 use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
+use TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException;
 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
 
@@ -144,11 +145,14 @@ class AbstractWidgetViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
      */
     public function initiateSubRequestThrowsExceptionIfControllerIsNoWidgetController()
     {
-        $controller = $this->getMock('Tx_Fluid_MVC_Controller_ControllerInterface');
+        $controller = $this->getMock(AbstractWidgetViewHelper::class);
+
+        $this->expectException(MissingControllerException::class);
+        $this->expectExceptionCode(1289422564);
+
         $this->viewHelper->_set('controller', $controller);
         $this->viewHelper->_call('initiateSubRequest');
     }
index d36f3f7..2a8e971 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetContextNotFoundException;
 
 /**
  * Test case
@@ -21,12 +22,15 @@ class AjaxWidgetContextHolderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 {
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetContextNotFoundException
      */
     public function getThrowsExceptionIfWidgetContextIsNotFound()
     {
         /** @var \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder $ajaxWidgetContextHolder */
         $ajaxWidgetContextHolder = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class, array('dummy'), array(), '', false);
+
+        $this->expectException(WidgetContextNotFoundException::class);
+        $this->expectExceptionCode(1284793775);
+
         $ajaxWidgetContextHolder->get(42);
     }
 }
index a47387d..8474cdc 100644 (file)
@@ -493,7 +493,6 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
      */
     public function selectOnDomainObjectsThrowsExceptionIfNoValueCanBeFound()
     {
@@ -501,6 +500,9 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
         $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue(null));
         $this->viewHelper->_set('persistenceManager', $mockPersistenceManager);
 
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
+        $this->expectExceptionCode(1247826696);
+
         $user = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
 
         $this->arguments['options'] = array(
index 93c1d1f..4f37508 100644 (file)
@@ -55,10 +55,12 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
      */
     public function viewHelperThrowsExceptionIfIncorrectModeIsGiven()
     {
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
+        $this->expectExceptionCode(1358349150);
+
         $this->subject->render('Foo', 'incorrectMode');
     }
 
index 4263a2c..ef1db05 100644 (file)
@@ -153,11 +153,12 @@ class DateViewHelperTest extends UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
-     * @expectedExceptionMessageRegExp /"foo" could not be parsed by \\DateTime constructor: .* Unexpected character$/
      */
     public function viewHelperThrowsExceptionWithOriginalMessageIfDateStringCantBeParsed()
     {
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
+        $this->expectExceptionCode(1241722579);
+
         $this->subject->render('foo');
     }
 
index 23182d0..3a130f8 100644 (file)
@@ -39,7 +39,6 @@ class ImageViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
      * @dataProvider getInvalidArguments
      * @param array $arguments
      */
@@ -47,6 +46,10 @@ class ImageViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $mock = $this->getMock(ImageViewHelper::class, array('dummy'));
         $mock->setArguments($arguments);
+
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
+        $this->expectExceptionCode(1382284106);
+
         $mock->render(
             isset($arguments['src']) ? $arguments['src'] : null,
             isset($arguments['width']) ? $arguments['width'] : null,
index 67b21cf..abf9c60 100644 (file)
@@ -30,13 +30,15 @@ class TranslateViewHelperTest extends ViewHelperBaseTestcase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
-     * @expectedExceptionCode 1351584844
      */
     public function renderThrowsExceptionIfNoKeyOrIdParameterIsGiven()
     {
         $this->subject = GeneralUtility::makeInstance(TranslateViewHelper::class);
         $this->injectDependenciesIntoViewHelper($this->subject);
+
+        $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
+        $this->expectExceptionCode(1351584844);
+
         $this->subject->render();
     }