diff --git a/tests/unit/Config/DatabaseTest.php b/tests/unit/Config/DatabaseTest.php index 08bb0ebe76..1f028f32fb 100644 --- a/tests/unit/Config/DatabaseTest.php +++ b/tests/unit/Config/DatabaseTest.php @@ -1,5 +1,6 @@ time_zone)->equals(Env::$db_timezone_offset); } -} \ No newline at end of file + + function testItRethrowsPDOExceptions() { + $message = 'Error message'; + $pdo = Stub::make( + 'PDO', + array( + 'prepare' => function() use ($message) { + throw new \PDOException($message); + } + ) + ); + \ORM::setDb($pdo); + try { + $this->database->setupDriverOptions(); + $this->fail('Exception was not thrown'); + } catch(\Exception $e) { + expect($e instanceof \PDOException)->false(); + expect($e->getMessage())->equals($message); + } + // Remove the DB stub + $this->_before(); + } +} diff --git a/tests/unit/Models/ModelTest.php b/tests/unit/Models/ModelTest.php new file mode 100644 index 0000000000..ab53721770 --- /dev/null +++ b/tests/unit/Models/ModelTest.php @@ -0,0 +1,29 @@ + function() use ($message) { + throw new \PDOException($message); + } + ) + ); + \ORM::setDb($pdo); + try { + $model::findMany(); + $this->fail('Exception was not thrown'); + } catch(\Exception $e) { + expect($e instanceof \PDOException)->false(); + expect($e->getMessage())->equals($message); + } + // Remove the DB stub + \ORM::setDb(null); + } +}