From e1ddf7f0127e9745f94e5ff9f76ea828e9058720 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 15 Sep 2014 22:35:56 +0200 Subject: Run unit tests across different database backends + fix bugs --- tests/units/Base.php | 100 ++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 69 deletions(-) (limited to 'tests/units/Base.php') diff --git a/tests/units/Base.php b/tests/units/Base.php index cea9764c..3a46a4ae 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -1,86 +1,48 @@ setPath('app'); +$loader->setPath('vendor'); +$loader->execute(); abstract class Base extends PHPUnit_Framework_TestCase { public function setUp() { - date_default_timezone_set('UTC'); - - $this->registry = new \Core\Registry; - $this->registry->db = $this->getDbConnection(); - $this->registry->event = new \Core\Event; + $this->registry = new Registry; + $this->registry->db = function() { return setup_db(); }; + $this->registry->event = function() { return setup_events(); }; + + if (DB_DRIVER === 'mysql') { + $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD); + $pdo->exec('DROP DATABASE '.DB_NAME); + $pdo->exec('CREATE DATABASE '.DB_NAME); + $pdo = null; + } + else if (DB_DRIVER === 'postgres') { + $pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD); + $pdo->exec('DROP DATABASE '.DB_NAME); + $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME); + $pdo = null; + } } - public function getDbConnection() + public function tearDown() { - $db = new \PicoDb\Database(array( - 'driver' => 'sqlite', - 'filename' => ':memory:' - )); - - if ($db->schema()->check(\Schema\VERSION)) { - return $db; - } - else { - die('Unable to migrate database schema!'); - } + $this->registry->shared('db')->closeConnection(); } } -- cgit v1.2.3