Permalink
Browse files

Merged PostgreSQL and MySQL tests inti one PHPUnit XML config.

  • Loading branch information...
corpsee committed Feb 28, 2018
1 parent 27f3819 commit 8d0d23f5f421b7a921f1ac097c432fcf7e372a0f
View
@@ -11,7 +11,7 @@ setup:
test:
php_unit:
config:
- phpunit.pgsql.xml
- phpunit.xml
php_mess_detector:
allow_failures: true
View
@@ -15,20 +15,16 @@ php:
matrix:
fast_finish: true
env:
- TYPE=mysql
- TYPE=pgsql
install:
- composer selfupdate
- composer install
before_script:
- if [[ "$TYPE" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS b8_test;" -uroot; fi
- if [[ "$TYPE" == "pgsql" ]]; then psql -c 'create database b8_test;' -U postgres; fi
- mysql -e "create database IF NOT EXISTS b8_test;" -uroot
- psql -c 'create database b8_test;' -U postgres
script:
- vendor/bin/phpunit --configuration phpunit.$TYPE.xml --coverage-clover=coverage.xml
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml
after_success:
- bash <(curl -s https://codecov.io/bash)
View

This file was deleted.

Oops, something went wrong.
@@ -12,10 +12,12 @@
bootstrap="./tests/bootstrap.php"
>
<php>
<env name="DB_TYPE" value="mysql" />
<env name="DB_USER" value="root" />
<env name="DB_PASS" value="" />
<env name="DB_NAME" value="b8_test" />
<env name="MYSQL_USER" value="root" />
<env name="MYSQL_PASSWORD" value="" />
<env name="MYSQL_DBNAME" value="b8_test" />
<env name="POSTGRESQL_USER" value="postgres" />
<env name="POSTGRESQL_PASSWORD" value="" />
<env name="POSTGRESQL_DBNAME" value="b8_test" />
</php>
<testsuites>
<testsuite name="B8Framework Test Suite">
@@ -103,7 +103,7 @@ public static function getConnection($type = 'read')
}
// No connection? Oh dear.
if (!$connection && $type == 'read') {
if (!$connection && $type === 'read') {
throw new \Exception('Could not connect to any ' . $type . ' servers.');
}
@@ -4,8 +4,9 @@
use b8\Config;
use b8\Database;
use PHPUnit\Framework\TestCase;
class DatabaseTest extends \PHPUnit\Framework\TestCase
class DatabaseMysqlTest extends TestCase
{
protected function setUp()
{
@@ -20,13 +21,14 @@ protected function setUp()
['host' => 'localhost'],
],
],
'type' => DB_TYPE,
'name' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASS,
'type' => 'mysql',
'name' => MYSQL_DBNAME,
'username' => MYSQL_USER,
'password' => MYSQL_PASSWORD,
],
],
]);
Database::reset();
}
protected function checkDatabaseConnection()
@@ -56,9 +58,9 @@ public function testGetDetails()
$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));
self::assertTrue(($details['db'] === MYSQL_DBNAME));
self::assertTrue(($details['user'] === MYSQL_USER));
self::assertTrue(($details['pass'] === MYSQL_PASSWORD));
}
/**
@@ -81,7 +83,7 @@ public function testConnectionFailure()
['host' => 'localhost'],
],
],
'type' => DB_TYPE,
'type' => 'mysql',
'name' => 'b8_test_2',
'username' => '',
'password' => '',
@@ -0,0 +1,96 @@
<?php
namespace Tests\b8;
use b8\Config;
use b8\Database;
use PHPUnit\Framework\TestCase;
class DatabasePostgresqlTest extends TestCase
{
protected function setUp()
{
$config = new Config([
'b8' => [
'database' => [
'servers' => [
'read' => [
['host' => 'localhost'],
],
'write' => [
['host' => 'localhost'],
],
],
'type' => 'pgsql',
'name' => POSTGRESQL_DBNAME,
'username' => POSTGRESQL_USER,
'password' => POSTGRESQL_PASSWORD,
],
],
]);
Database::reset();
}
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'] === POSTGRESQL_DBNAME));
self::assertTrue(($details['user'] === POSTGRESQL_USER));
self::assertTrue(($details['pass'] === POSTGRESQL_PASSWORD));
}
/**
* @expectedException \Exception
*/
public function testConnectionFailure()
{
$this->checkDatabaseConnection();
Database::reset();
$config = new Config([
'b8' => [
'database' => [
'servers' => [
'read' => [
['host' => 'localhost'],
],
'write' => [
['host' => 'localhost'],
],
],
'type' => 'pgsql',
'name' => 'b8_test_2',
'username' => '',
'password' => '',
],
],
]);
Database::getConnection('read');
}
}
@@ -83,7 +83,7 @@ public function testSkippedAnything()
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'],
];
}
View
@@ -45,7 +45,10 @@
\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'));
define('MYSQL_DBNAME', getenv('MYSQL_DBNAME'));
define('MYSQL_USER', getenv('MYSQL_USER'));
define('MYSQL_PASSWORD', getenv('MYSQL_PASSWORD'));
define('POSTGRESQL_DBNAME', getenv('POSTGRESQL_DBNAME'));
define('POSTGRESQL_USER', getenv('POSTGRESQL_USER'));
define('POSTGRESQL_PASSWORD', getenv('POSTGRESQL_PASSWORD'));

0 comments on commit 8d0d23f

Please sign in to comment.