Add tests for PDO exceptions rethrowing [MAILPOET-966]
This commit is contained in:
committed by
pavel-mailpoet
parent
693117eb40
commit
d5227a9f2c
29
tests/unit/Models/ModelTest.php
Normal file
29
tests/unit/Models/ModelTest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use MailPoet\Models\Model;
|
||||
|
||||
class ModelTest extends MailPoetTest {
|
||||
function testItRethrowsPDOExceptions() {
|
||||
$message = 'Error message';
|
||||
$model = Stub::make('MailPoet\Models\Model');
|
||||
$pdo = Stub::make(
|
||||
'PDO',
|
||||
array(
|
||||
'prepare' => 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user