Merged PostgreSQL and MySQL tests inti one PHPUnit XML config.
This commit is contained in:
parent
27f381982a
commit
8d0d23f5f4
|
@ -11,7 +11,7 @@ setup:
|
|||
test:
|
||||
php_unit:
|
||||
config:
|
||||
- phpunit.pgsql.xml
|
||||
- phpunit.xml
|
||||
|
||||
php_mess_detector:
|
||||
allow_failures: true
|
||||
|
|
10
.travis.yml
10
.travis.yml
|
@ -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)
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="./tests/bootstrap.php"
|
||||
>
|
||||
<php>
|
||||
<env name="DB_TYPE" value="pgsql" />
|
||||
<env name="DB_USER" value="postgres" />
|
||||
<env name="DB_PASS" value="" />
|
||||
<env name="DB_NAME" value="b8_test" />
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="B8Framework Test Suite">
|
||||
<directory suffix="Test.php">./tests/B8Framework</directory>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="PHP Censor Helper Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Helper</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Controller Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Controller</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Logging Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Logging</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Model Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Model</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Plugin Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Plugin</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Service Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Service</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Command Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Command</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor ProcessControl Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Security Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Security</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">./src/PHPCensor/Migrations</directory>
|
||||
<directory suffix=".php">./src/PHPCensor/Languages</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
|
@ -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 @@ class Database extends \PDO
|
|||
}
|
||||
|
||||
// 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 @@ namespace Tests\b8;
|
|||
|
||||
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 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
|
|||
['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 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$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 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
|
|||
['host' => 'localhost'],
|
||||
],
|
||||
],
|
||||
'type' => DB_TYPE,
|
||||
'type' => 'mysql',
|
||||
'name' => 'b8_test_2',
|
||||
'username' => '',
|
||||
'password' => '',
|
96
tests/B8Framework/DatabasePostgresqlTest.php
Executable file
96
tests/B8Framework/DatabasePostgresqlTest.php
Executable file
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -45,7 +45,10 @@ if (!defined('APP_URL') && !empty($config)) {
|
|||
|
||||
\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'));
|
||||
|
|
Loading…
Reference in a new issue