Share PDO connection between Doctrine and legacy ORM

[MAILPOET-2014]
This commit is contained in:
Jan Jakeš
2019-07-18 15:40:15 +02:00
committed by M. Shull
parent a07043cfb4
commit 0045683d92
8 changed files with 41 additions and 130 deletions

View File

@ -1,7 +1,7 @@
<?php
namespace MailPoet\Test\Config;
use Codeception\Util\Stub;
use MailPoet\Config\Database;
use MailPoet\Config\Env;
@ -26,29 +26,8 @@ class DatabaseTest extends \MailPoetTest {
expect(\ORM::get_config('logging'))->equals(WP_DEBUG);
}
function testItSetsUpConnection() {
expect(\ORM::get_config('username'))->equals(Env::$db_username);
expect(\ORM::get_config('password'))->equals(Env::$db_password);
}
function testItSelectivelyUpdatesDriverTimeoutOption() {
$database = $this->database;
$database->setupDriverOptions();
$current_setting = \ORM::for_table("")
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
->findOne();
expect($current_setting->wait_timeout)->greaterThan($database->driver_option_wait_timeout);
$this->_before();
$database->driver_option_wait_timeout = 99999;
$database->setupDriverOptions();
$current_setting = \ORM::for_table("")
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
->findOne();
expect($current_setting->wait_timeout)->equals(99999);
}
function testItSetsDBDriverOptions() {
$this->database->init();
$this->database->init($this->connection->getWrappedConnection());
$result = \ORM::for_table("")
->raw_query(
'SELECT ' .
@ -61,26 +40,4 @@ class DatabaseTest extends \MailPoetTest {
// time zone should be set based on WP's time zone
expect($result->time_zone)->equals(Env::$db_timezone_offset);
}
function testItRethrowsPDOExceptions() {
$message = 'Error message';
$pdo = Stub::make(
'PDO',
[
'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();
}
}