From 9f0580e8020869fea092fd2dbe7d57edc25539df Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 18 Feb 2017 10:31:33 +0700 Subject: [PATCH] Improved TravisCI build settings --- .php-censor.yml | 2 +- .travis.yml | 16 ++++- README.md | 14 +++-- phpunit.xml => phpunit.mysql.xml | 6 ++ phpunit.pgsql.xml | 58 +++++++++++++++++++ .../Plugin/Option/PhpUnitOptions.php | 2 + tests/B8Framework/DatabaseTest.php | 14 ++--- tests/bootstrap.php | 5 ++ 8 files changed, 104 insertions(+), 13 deletions(-) rename phpunit.xml => phpunit.mysql.xml (91%) create mode 100644 phpunit.pgsql.xml diff --git a/.php-censor.yml b/.php-censor.yml index 584aa0ea..4f4bf834 100644 --- a/.php-censor.yml +++ b/.php-censor.yml @@ -10,7 +10,7 @@ setup: test: php_unit: config: - - phpunit.xml + - phpunit.mysql.xml coverage: coverage php_mess_detector: diff --git a/.travis.yml b/.travis.yml index 4a990e98..b84fb633 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,11 @@ language: php +sudo: false + +cache: + directories: + - $HOME/.composer/cache + php: - 5.6 - 7.0 @@ -8,12 +14,20 @@ 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 + script: - - ./vendor/bin/phpunit + - vendor/bin/phpunit --configuration phpunit.$TYPE.xml --coverage-text notifications: email: diff --git a/README.md b/README.md index 2994aa57..9f846f71 100644 --- a/README.md +++ b/README.md @@ -191,13 +191,19 @@ Tests ```bash cd /path/to/php-censor -./vendor/bin/phpunit + +# For testing on MySQL DB +./vendor/bin/phpunit --configuration ./phpunit.mysql.xml + +# For testing on PostgreSQL +./vendor/bin/phpunit --configuration ./phpunit.pgsql.xml ``` -For Phar plugin tests set 'phar.readonly' setting to Off (0) in `php.ini` config. Otherwise tests will be skipped. +For Phar plugin tests set 'phar.readonly' setting to Off (0) in `php.ini` config. Otherwise tests will be skipped. -For database B8Framework tests create empty 'b8_test' database on 'localhost' with user/password: `root/root`. -Otherwise database tests will be skipped. +For database B8Framework tests create empty 'b8_test' database on 'localhost' with user/password: `root/'` +for MySQL and with user/password: `postgres/'` for PostgreSQL (You can change default test user, password and +database name in `phpunit.mysql|pgsql.xml` config). If connection failed tests will be skipped. Documentation ------------- diff --git a/phpunit.xml b/phpunit.mysql.xml similarity index 91% rename from phpunit.xml rename to phpunit.mysql.xml index 5c1a9c76..64799bb2 100644 --- a/phpunit.xml +++ b/phpunit.mysql.xml @@ -11,6 +11,12 @@ syntaxCheck="false" bootstrap="./tests/bootstrap.php" > + + + + + + ./tests/B8Framework diff --git a/phpunit.pgsql.xml b/phpunit.pgsql.xml new file mode 100644 index 00000000..28522543 --- /dev/null +++ b/phpunit.pgsql.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + ./tests/B8Framework + + + + ./tests/PHPCensor/Helper + + + ./tests/PHPCensor/Controller + + + ./tests/PHPCensor/Logging + + + ./tests/PHPCensor/Model + + + ./tests/PHPCensor/Plugin + + + ./tests/PHPCensor/Service + + + ./tests/PHPCensor/Command + + + ./tests/PHPCensor/ProcessControl + + + ./tests/PHPCensor/Security + + + + + ./src + + + diff --git a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php index a091b13f..ea91d3ea 100644 --- a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php +++ b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php @@ -257,6 +257,8 @@ class PhpUnitOptions { $files = [ 'phpunit.xml', + 'phpunit.mysql.xml', + 'phpunit.pgsql.xml', 'phpunit.xml.dist', 'tests/phpunit.xml', 'tests/phpunit.xml.dist', diff --git a/tests/B8Framework/DatabaseTest.php b/tests/B8Framework/DatabaseTest.php index 636555e0..680a2a9d 100755 --- a/tests/B8Framework/DatabaseTest.php +++ b/tests/B8Framework/DatabaseTest.php @@ -20,10 +20,10 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase ['host' => 'localhost'], ], ], - 'type' => 'mysql', - 'name' => 'b8_test', - 'username' => 'root', - 'password' => 'root', + 'type' => DB_TYPE, + 'name' => DB_NAME, + 'username' => DB_USER, + 'password' => DB_PASS, ], ], ]); @@ -56,9 +56,9 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase $details = Database::getConnection('read')->getDetails(); $this->assertTrue(is_array($details)); - $this->assertTrue(($details['db'] == 'b8_test')); - $this->assertTrue(($details['user'] == 'root')); - $this->assertTrue(($details['pass'] == 'root')); + $this->assertTrue(($details['db'] == DB_NAME)); + $this->assertTrue(($details['user'] == DB_USER)); + $this->assertTrue(($details['pass'] == DB_PASS)); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e90c3bd5..f7e42b62 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -51,3 +51,8 @@ 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'));