Browse Source

Added test for handling of PHP 7 errors

Jose Lorenzo Rodriguez 10 years ago
parent
commit
fc5ce30405
1 changed files with 17 additions and 0 deletions
  1. 17 0
      tests/TestCase/Error/ErrorHandlerTest.php

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

@@ -21,6 +21,7 @@ use Cake\Core\Plugin;
 use Cake\Error;
 use Cake\Error\ErrorHandler;
 use Cake\Error\ExceptionRenderer;
+use Cake\Error\PHP7ErrorException;
 use Cake\Log\Log;
 use Cake\Network\Exception\ForbiddenException;
 use Cake\Network\Exception\NotFoundException;
@@ -29,6 +30,7 @@ use Cake\Network\Response;
 use Cake\Routing\Exception\MissingControllerException;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
+use ParseError;
 
 /**
  * Testing stub.
@@ -416,4 +418,19 @@ class ErrorHandlerTest extends TestCase
         $errorHandler = new TestErrorHandler(['log' => true]);
         $errorHandler->handleFatalError(E_ERROR, 'Something wrong', __FILE__, __LINE__);
     }
+
+    /**
+     * Tests Handling a PHP7 error
+     *
+     * @return void
+     */
+    public function testHandlePHP7Error()
+    {
+        $this->skipIf(!class_exists('Error'), 'Requires PHP7');
+        $error = new PHP7ErrorException(new ParseError('Unexpected variable foo'));
+        $errorHandler = new TestErrorHandler();
+
+        $errorHandler->handleException($error);
+        $this->assertContains('Unexpected variable foo', $errorHandler->response->body(), 'message missing.');
+    }
 }