diff --git a/tests/B8Framework/DatabaseMysqlTest.php b/tests/B8Framework/DatabaseMysqlTest.php
new file mode 100755
index 00000000..139f4d81
--- /dev/null
+++ b/tests/B8Framework/DatabaseMysqlTest.php
@@ -0,0 +1,231 @@
+connection) {
+ try {
+ $pdo = new \PDO(
+ 'mysql:host=localhost;dbname=' . MYSQL_DBNAME,
+ MYSQL_USER,
+ MYSQL_PASSWORD
+ );
+
+ $this->connection = $this->createDefaultDBConnection($pdo, MYSQL_DBNAME);
+
+ $this->connection->getConnection()->query('
+ CREATE TABLE IF NOT EXISTS `database_mysql_test` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `projectId` int(11) NOT NULL,
+ `branch` varchar(250) NOT NULL DEFAULT \'master\',
+ `createDate` datetime,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ ');
+ } catch (\PDOException $ex) {
+ $this->connection = null;
+ }
+ }
+ } else {
+ $this->connection = null;
+ }
+ }
+
+ /**
+ * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection
+ */
+ protected function getConnection()
+ {
+ if (null === $this->connection) {
+ $this->markTestSkipped('Test skipped because MySQL database/user/extension doesn`t exist.');
+ }
+
+ return $this->connection;
+ }
+
+ /**
+ * @return \PHPUnit_Extensions_Database_DataSet_IDataSet
+ */
+ protected function getDataSet()
+ {
+ return $this->createArrayDataSet([
+ 'database_mysql_test' => [[
+ 'id' => 1,
+ 'projectId' => 1,
+ 'branch' => 'master',
+ 'createDate' => null,
+ ], [
+ 'id' => 2,
+ 'projectId' => 2,
+ 'branch' => 'dev',
+ 'createDate' => '2018-02-20 01:01:01',
+ ], [
+ 'id' => 3,
+ 'projectId' => 2,
+ 'branch' => 'master',
+ 'createDate' => '2018-02-21 02:02:02',
+ ]],
+ ]);
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ ['host' => 'localhost'],
+ ],
+ 'write' => [
+ ['host' => 'localhost'],
+ ],
+ ],
+ 'type' => Database::MYSQL_TYPE,
+ 'name' => MYSQL_DBNAME,
+ 'username' => MYSQL_USER,
+ 'password' => MYSQL_PASSWORD,
+ ],
+ ],
+ ]);
+ Database::reset();
+ }
+
+ public function testGetConnection()
+ {
+ $writeConnection = Database::getConnection('write');
+ $readConnection = Database::getConnection('read');
+
+ self::assertInstanceOf('\b8\Database', $writeConnection);
+ self::assertInstanceOf('\b8\Database', $readConnection);
+
+ $writeDetails = $writeConnection->getDetails();
+
+ self::assertTrue(is_array($writeDetails));
+ self::assertEquals(MYSQL_DBNAME, $writeDetails['db']);
+ self::assertEquals(MYSQL_USER, $writeDetails['user']);
+ self::assertEquals(MYSQL_PASSWORD, $writeDetails['pass']);
+
+ $readDetails = $readConnection->getDetails();
+
+ self::assertTrue(is_array($readDetails));
+ self::assertEquals(MYSQL_DBNAME, $readDetails['db']);
+ self::assertEquals(MYSQL_USER, $readDetails['user']);
+ self::assertEquals(MYSQL_PASSWORD, $readDetails['pass']);
+
+ self::assertEquals('mysql:host=localhost;dbname=b8_test', $readConnection->getDsn());
+ }
+
+ public function testGetWriteConnectionWithPort()
+ {
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ [
+ 'host' => 'localhost',
+ 'port' => 3306,
+ ],
+ ],
+ 'write' => [
+ [
+ 'host' => 'localhost',
+ 'port' => 3306,
+ ],
+ ],
+ ],
+ 'type' => Database::MYSQL_TYPE,
+ 'name' => MYSQL_DBNAME,
+ 'username' => MYSQL_USER,
+ 'password' => MYSQL_PASSWORD,
+ ],
+ ],
+ ]);
+ Database::reset();
+
+ $writeConnection = Database::getConnection('write');
+ $readConnection = Database::getConnection('read');
+
+ self::assertInstanceOf('\b8\Database', $writeConnection);
+ self::assertInstanceOf('\b8\Database', $readConnection);
+
+ self::assertEquals('mysql:host=localhost;port=3306;dbname=b8_test', $readConnection->getDsn());
+ }
+
+ /**
+ * @expectedException \Exception
+ */
+ public function testConnectionFailure()
+ {
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ ['host' => 'localhost'],
+ ],
+ 'write' => [
+ ['host' => 'localhost'],
+ ],
+ ],
+ 'type' => Database::MYSQL_TYPE,
+ 'name' => 'b8_test_2',
+ 'username' => '',
+ 'password' => '',
+ ],
+ ],
+ ]);
+ Database::reset();
+
+ Database::getConnection('read');
+ }
+
+ public function testPrepareCommon()
+ {
+ $readConnection = Database::getConnection('read');
+
+ $sql = 'SELECT * FROM {{database_mysql_test}} WHERE {{projectId}} = :projectId';
+ $query = $readConnection->prepareCommon($sql);
+
+ $query->bindValue(':projectId', 2);
+ $query->execute();
+
+ $data = $query->fetchAll(\PDO::FETCH_ASSOC);
+
+ self::assertEquals(2, count($data));
+ }
+
+ public function testLastInsertIdExtended()
+ {
+ $writeConnection = Database::getConnection('write');
+
+ $sql = 'INSERT INTO {{database_mysql_test}} ({{projectId}}) VALUES (3)';
+ $query = $writeConnection->prepareCommon($sql);
+
+ $query->execute();
+
+ self::assertEquals(4, $writeConnection->lastInsertIdExtended());
+ }
+}
diff --git a/tests/B8Framework/DatabasePostgresqlTest.php b/tests/B8Framework/DatabasePostgresqlTest.php
new file mode 100755
index 00000000..c571d6e4
--- /dev/null
+++ b/tests/B8Framework/DatabasePostgresqlTest.php
@@ -0,0 +1,235 @@
+connection) {
+ try {
+ $pdo = new \PDO(
+ 'pgsql:host=localhost;dbname=' . POSTGRESQL_DBNAME,
+ POSTGRESQL_USER,
+ POSTGRESQL_PASSWORD
+ );
+
+ $this->connection = $this->createDefaultDBConnection($pdo, POSTGRESQL_DBNAME);
+
+ $this->connection->getConnection()->query('
+ CREATE TABLE IF NOT EXISTS "database_mysql_test" (
+ "id" SERIAL,
+ "projectId" integer NOT NULL,
+ "branch" character varying(250) NOT NULL DEFAULT \'master\',
+ "createDate" timestamp without time zone,
+ PRIMARY KEY ("id")
+ );
+ ');
+ } catch (\PDOException $ex) {
+ $this->connection = null;
+ }
+ }
+ } else {
+ $this->connection = null;
+ }
+ }
+
+ /**
+ * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection
+ */
+ protected function getConnection()
+ {
+ if (null === $this->connection) {
+ $this->markTestSkipped('Test skipped because PostgreSQL database/user/extension doesn`t exist.');
+ }
+
+ return $this->connection;
+ }
+
+ /**
+ * @return \PHPUnit_Extensions_Database_DataSet_IDataSet
+ */
+ protected function getDataSet()
+ {
+ return $this->createArrayDataSet([
+ 'database_mysql_test' => [[
+ 'id' => 1,
+ 'projectId' => 1,
+ 'branch' => 'master',
+ 'createDate' => null,
+ ], [
+ 'id' => 2,
+ 'projectId' => 2,
+ 'branch' => 'dev',
+ 'createDate' => '2018-02-20 01:01:01',
+ ], [
+ 'id' => 3,
+ 'projectId' => 2,
+ 'branch' => 'master',
+ 'createDate' => '2018-02-21 02:02:02',
+ ]],
+ ]);
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ ['host' => 'localhost'],
+ ],
+ 'write' => [
+ ['host' => 'localhost'],
+ ],
+ ],
+ 'type' => Database::POSTGRESQL_TYPE,
+ 'name' => POSTGRESQL_DBNAME,
+ 'username' => POSTGRESQL_USER,
+ 'password' => POSTGRESQL_PASSWORD,
+ ],
+ ],
+ ]);
+ Database::reset();
+ }
+
+ public function testGetConnection()
+ {
+ $writeConnection = Database::getConnection('write');
+ $readConnection = Database::getConnection('read');
+
+ self::assertInstanceOf('\b8\Database', $writeConnection);
+ self::assertInstanceOf('\b8\Database', $readConnection);
+
+ $writeDetails = $writeConnection->getDetails();
+
+ self::assertTrue(is_array($writeDetails));
+ self::assertEquals(POSTGRESQL_DBNAME, $writeDetails['db']);
+ self::assertEquals(POSTGRESQL_USER, $writeDetails['user']);
+ self::assertEquals(POSTGRESQL_PASSWORD, $writeDetails['pass']);
+
+ $readDetails = $readConnection->getDetails();
+
+ self::assertTrue(is_array($readDetails));
+ self::assertEquals(POSTGRESQL_DBNAME, $readDetails['db']);
+ self::assertEquals(POSTGRESQL_USER, $readDetails['user']);
+ self::assertEquals(POSTGRESQL_PASSWORD, $readDetails['pass']);
+
+ self::assertEquals('pgsql:host=localhost;dbname=b8_test', $readConnection->getDsn());
+ }
+
+ public function testGetWriteConnectionWithPort()
+ {
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ [
+ 'host' => 'localhost',
+ 'port' => 5432,
+ ],
+ ],
+ 'write' => [
+ [
+ 'host' => 'localhost',
+ 'port' => 5432,
+ ],
+ ],
+ ],
+ 'type' => Database::POSTGRESQL_TYPE,
+ 'name' => POSTGRESQL_DBNAME,
+ 'username' => POSTGRESQL_USER,
+ 'password' => POSTGRESQL_PASSWORD,
+ ],
+ ],
+ ]);
+ Database::reset();
+
+ $writeConnection = Database::getConnection('write');
+ $readConnection = Database::getConnection('read');
+
+ self::assertInstanceOf('\b8\Database', $writeConnection);
+ self::assertInstanceOf('\b8\Database', $readConnection);
+
+ self::assertEquals('pgsql:host=localhost;port=5432;dbname=b8_test', $readConnection->getDsn());
+ }
+
+ /**
+ * @expectedException \Exception
+ */
+ public function testConnectionFailure()
+ {
+ new Config([
+ 'b8' => [
+ 'database' => [
+ 'servers' => [
+ 'read' => [
+ ['host' => 'localhost'],
+ ],
+ 'write' => [
+ ['host' => 'localhost'],
+ ],
+ ],
+ 'type' => Database::POSTGRESQL_TYPE,
+ 'name' => 'b8_test_2',
+ 'username' => '',
+ 'password' => '',
+ ],
+ ],
+ ]);
+ Database::reset();
+
+ Database::getConnection('read');
+ }
+
+ public function testPrepareCommon()
+ {
+ $readConnection = Database::getConnection('read');
+
+ $sql = 'SELECT * FROM {{database_mysql_test}} WHERE {{projectId}} = :projectId';
+ $query = $readConnection->prepareCommon($sql);
+
+ $query->bindValue(':projectId', 2);
+ $query->execute();
+
+ $data = $query->fetchAll(\PDO::FETCH_ASSOC);
+
+ self::assertEquals(2, count($data));
+ }
+
+ public function testLastInsertIdExtended()
+ {
+ $this->connection->getConnection()->query('
+ ALTER SEQUENCE "database_mysql_test_id_seq" RESTART WITH 4;
+ ');
+
+ $writeConnection = Database::getConnection('write');
+
+ $sql = 'INSERT INTO {{database_mysql_test}} ({{projectId}}) VALUES (3)';
+ $query = $writeConnection->prepareCommon($sql);
+
+ $query->execute();
+
+ self::assertEquals(4, $writeConnection->lastInsertIdExtended('database_mysql_test'));
+ }
+}
diff --git a/tests/B8Framework/DatabaseTest.php b/tests/B8Framework/DatabaseTest.php
deleted file mode 100755
index 7a353e8d..00000000
--- a/tests/B8Framework/DatabaseTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
- [
- 'database' => [
- 'servers' => [
- 'read' => [
- ['host' => 'localhost'],
- ],
- 'write' => [
- ['host' => 'localhost'],
- ],
- ],
- 'type' => DB_TYPE,
- 'name' => DB_NAME,
- 'username' => DB_USER,
- 'password' => DB_PASS,
- ],
- ],
- ]);
- }
-
- protected function checkDatabaseConnection()
- {
- try {
- $connection = Database::getConnection('read');
- } catch (\Exception $e) {
- if ('Could not connect to any read servers.' === $e->getMessage()) {
- $this->markTestSkipped('Test skipped because test database doesn`t exist.');
- } else {
- throw $e;
- }
- }
- }
-
- public function testGetWriteConnection()
- {
- $this->checkDatabaseConnection();
-
- $connection = Database::getConnection('write');
- self::assertInstanceOf('\b8\Database', $connection);
- }
-
- public function testGetDetails()
- {
- $this->checkDatabaseConnection();
-
- $details = Database::getConnection('read')->getDetails();
- self::assertTrue(is_array($details));
- self::assertTrue(($details['db'] == DB_NAME));
- self::assertTrue(($details['user'] == DB_USER));
- self::assertTrue(($details['pass'] == DB_PASS));
- }
-
- /**
- * @expectedException \Exception
- */
- public function testConnectionFailure()
- {
- $this->checkDatabaseConnection();
-
- Database::reset();
-
- $config = new Config([
- 'b8' => [
- 'database' => [
- 'servers' => [
- 'read' => [
- ['host' => 'localhost'],
- ],
- 'write' => [
- ['host' => 'localhost'],
- ],
- ],
- 'type' => DB_TYPE,
- 'name' => 'b8_test_2',
- 'username' => '',
- 'password' => '',
- ],
- ],
- ]);
-
- Database::getConnection('read');
- }
-}
diff --git a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php
index 58d119b8..9eeaa50a 100644
--- a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php
+++ b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php
@@ -83,7 +83,7 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase
public static function getTestData()
{
return [
- 'json' => [PhpUnitResultJson::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt'],
+ 'json' => [PhpUnitResultJson::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt'],
'junit' => [PhpUnitResultJunit::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml'],
];
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index f308bdc6..113bf8bf 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,51 +1,42 @@
loadYaml($configFile);
-}
-
if (!defined('APP_URL') && !empty($config)) {
define('APP_URL', $config->get('php-censor.url', '') . '/');
}
-\PHPCensor\Helper\Lang::init($config, 'en');
-
-define('DB_NAME', getenv('DB_NAME'));
-define('DB_USER', getenv('DB_USER'));
-define('DB_TYPE', getenv('DB_TYPE'));
-define('DB_PASS', getenv('DB_PASS'));
+\PHPCensor\Helper\Lang::init($config);