Browse Source

wrap tests by error reporting helpers

saeid 8 years ago
parent
commit
2d196e827e

+ 0 - 1
tests/TestCase/BasicsTest.php

@@ -592,5 +592,4 @@ EXPECTED;
         $this->assertInstanceOf(EventManager::class, $prevEventManager);
         $this->assertNotSame($prevEventManager, EventManager::instance());
     }
-
 }

+ 4 - 2
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -1105,13 +1105,15 @@ class RequestHandlerComponentTest extends TestCase
     /**
      * testAddInputTypeException method
      *
+     * @group deprecated
      * @expectedException \Cake\Core\Exception\Exception
      * @return void
      */
     public function testAddInputTypeException()
     {
-        $restore = error_reporting(E_ALL & ~E_USER_DEPRECATED);
-        $this->RequestHandler->addInputType('csv', ['I am not callable']);
+        $this->deprecated(function () {
+            $this->RequestHandler->addInputType('csv', ['I am not callable']);
+        });
     }
 
     /**

+ 7 - 5
tests/TestCase/Controller/ControllerTest.php

@@ -1121,9 +1121,10 @@ class ControllerTest extends TestCase
      */
     public function testDeprecatedViewPropertySetterMessage($property, $getter, $setter, $value)
     {
-        error_reporting(E_ALL);
         $controller = new AnotherTestController();
-        $controller->$property = $value;
+        $this->withErrorReporting(E_ALL, function () use ($controller, $property, $value) {
+            $controller->$property = $value;
+        });
     }
 
     /**
@@ -1140,10 +1141,11 @@ class ControllerTest extends TestCase
      */
     public function testDeprecatedViewPropertyGetterMessage($property, $getter, $setter, $value)
     {
-            error_reporting(E_ALL);
-            $controller = new AnotherTestController();
-            $controller->viewBuilder()->{$setter}($value);
+        $controller = new AnotherTestController();
+        $controller->viewBuilder()->{$setter}($value);
+        $this->withErrorReporting(E_ALL, function () use ($controller, $property) {
             $result = $controller->$property;
+        });
     }
 
     /**

+ 11 - 8
tests/TestCase/Core/FunctionsTest.php

@@ -47,24 +47,26 @@ class FunctionsTest extends TestCase
      * Test error messages coming out when debug is on, manually setting the stack frame
      *
      * @expectedException PHPUnit\Framework\Error\Deprecated
-     * @expectedExceptionMessage This is going away - [internal], line: ??
+     * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
      */
     public function testDeprecationWarningEnabled()
     {
-        error_reporting(E_ALL);
-        deprecationWarning('This is going away', 1);
+        $this->withErrorReporting(E_ALL, function () {
+            deprecationWarning('This is going away', 1);
+        });
     }
 
     /**
      * Test error messages coming out when debug is on, not setting the stack frame manually
      *
      * @expectedException PHPUnit\Framework\Error\Deprecated
-     * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
+     * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]FunctionsTest.php, line\: \d+/
      */
     public function testDeprecationWarningEnabledDefaultFrame()
     {
-        error_reporting(E_ALL);
-        deprecationWarning('This is going away');
+        $this->withErrorReporting(E_ALL, function () {
+            deprecationWarning('This is going away');
+        });
     }
 
     /**
@@ -74,8 +76,9 @@ class FunctionsTest extends TestCase
      */
     public function testDeprecationWarningLevelDisabled()
     {
-        error_reporting(E_ALL ^ E_USER_DEPRECATED);
-        $this->assertNull(deprecationWarning('This is going away'));
+        $this->withErrorReporting(E_ALL ^ E_USER_DEPRECATED, function () {
+            $this->assertNull(deprecationWarning('This is going away'));
+        });
     }
 
     /**

+ 18 - 0
tests/TestCase/Error/ErrorHandlerTest.php

@@ -71,6 +71,12 @@ class ErrorHandlerTest extends TestCase
     protected $_restoreError = false;
 
     /**
+     * error level property
+     *
+     */
+    private static $errorLevel;
+
+    /**
      * setup create a request object to get out of router later.
      *
      * @return void
@@ -108,6 +114,18 @@ class ErrorHandlerTest extends TestCase
             restore_error_handler();
             restore_exception_handler();
         }
+        error_reporting(self::$errorLevel);
+    }
+
+    /**
+     * setUpBeforeClass
+     *
+     * @return void
+     */
+    public static function setUpBeforeClass()
+    {
+        parent::setUpBeforeClass();
+        self::$errorLevel = error_reporting();
     }
 
     /**