diff --git a/src/Framework/ExceptionWrapper.php b/src/Framework/ExceptionWrapper.php index 312745c52bb..1105afa6ece 100644 --- a/src/Framework/ExceptionWrapper.php +++ b/src/Framework/ExceptionWrapper.php @@ -74,7 +74,10 @@ class PHPUnit_Framework_ExceptionWrapper extends PHPUnit_Framework_Exception public function __construct(Exception $e) { - parent::__construct($e->getMessage(), $e->getCode()); + // PDOException::getCode() is a string. + // @see http://php.net/manual/en/class.pdoexception.php#95812 + parent::__construct($e->getMessage(), (int) $e->getCode()); + $this->classname = get_class($e); $this->file = $e->getFile(); $this->line = $e->getLine(); diff --git a/tests/Regression/GitHub/1351.phpt b/tests/Regression/GitHub/1351.phpt index fe95d3ad946..1244d6d2bdc 100644 --- a/tests/Regression/GitHub/1351.phpt +++ b/tests/Regression/GitHub/1351.phpt @@ -14,11 +14,11 @@ PHPUnit_TextUI_Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann. -F.E. +F.E.E Time: %s, Memory: %sMb -There was 1 error: +There were 2 errors: 1) Issue1351Test::testExceptionPre RuntimeException: Expected rethrown exception. @@ -27,6 +27,10 @@ Caused by LogicException: Expected exception. %A +2) Issue1351Test::testPhpCoreLanguageException +PDOException: SQLSTATE[HY000]: General error: 1 no such table: php_wtf +%A + -- There was 1 failure: @@ -35,4 +39,4 @@ There was 1 failure: Expected failure. %A FAILURES! -Tests: 4, Assertions: 5, Failures: 1, Errors: 1. \ No newline at end of file +Tests: 5, Assertions: 5, Failures: 1, Errors: 2. \ No newline at end of file diff --git a/tests/Regression/GitHub/1351/Issue1351Test.php b/tests/Regression/GitHub/1351/Issue1351Test.php index 9dac75defce..6008b13bd7e 100644 --- a/tests/Regression/GitHub/1351/Issue1351Test.php +++ b/tests/Regression/GitHub/1351/Issue1351Test.php @@ -36,4 +36,13 @@ public function testExceptionPost() $this->assertNull($this->instance); $this->assertFalse(class_exists('ChildProcessClass1351', false), 'ChildProcessClass1351 is not loaded.'); } + + public function testPhpCoreLanguageException() + { + // User-space code cannot instantiate a PDOException with a string code, + // so trigger a real one. + $connection = new PDO('sqlite::memory:'); + $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $connection->query("DELETE FROM php_wtf WHERE exception_code = 'STRING'"); + } }