Add tests for PDO exceptions rethrowing [MAILPOET-966]
This commit is contained in:
committed by
pavel-mailpoet
parent
693117eb40
commit
d5227a9f2c
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Codeception\Util\Stub;
|
||||||
use MailPoet\Config\Database;
|
use MailPoet\Config\Database;
|
||||||
use MailPoet\Config\Env;
|
use MailPoet\Config\Env;
|
||||||
|
|
||||||
@ -58,4 +59,26 @@ class DatabaseTestTest extends MailPoetTest {
|
|||||||
// time zone should be set based on WP's time zone
|
// time zone should be set based on WP's time zone
|
||||||
expect($result->time_zone)->equals(Env::$db_timezone_offset);
|
expect($result->time_zone)->equals(Env::$db_timezone_offset);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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