From 8cd29d3600ad4b5be1476a7c04962d064b4c14dd Mon Sep 17 00:00:00 2001 From: Mitchell Hewes Date: Wed, 11 Jan 2017 11:41:54 +1100 Subject: [PATCH] docs and tests configuration for mysql support --- .travis.yml | 4 ++++ docs/config.markdown | 8 ++++---- docs/installation.markdown | 2 +- tests/ci/config.mysql.php | 7 +++++++ tests/functional/BaseApiTest.php | 9 +++++++++ tests/phpunit.functional.mysql.xml | 15 +++++++++++++++ tests/phpunit.unit.mysql.xml | 13 +++++++++++++ tests/unit/BaseTest.php | 5 +++++ 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 tests/ci/config.mysql.php create mode 100644 tests/phpunit.functional.mysql.xml create mode 100644 tests/phpunit.unit.mysql.xml diff --git a/.travis.yml b/.travis.yml index 65e5b05..324d516 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,14 @@ script: - ./node_modules/.bin/jshint assets/js/src/*.js - ./vendor/bin/phpunit -c tests/phpunit.unit.sqlite.xml - ./vendor/bin/phpunit -c tests/phpunit.unit.postgres.xml + - ./vendor/bin/phpunit -c tests/phpunit.unit.mysql.xml - ./vendor/bin/phpunit -c tests/phpunit.functional.sqlite.xml - cp ./tests/ci/config.postgres.php $TRAVIS_BUILD_DIR/config.php - ./vendor/bin/phpunit -c tests/phpunit.functional.postgres.xml tests/functional/ApiTest.php - ./vendor/bin/phpunit -c tests/phpunit.functional.postgres.xml tests/functional/FeverApiTest.php + - cp ./tests/ci/config.mysql.php $TRAVIS_BUILD_DIR/config.php + - ./vendor/bin/phpunit -c tests/phpunit.functional.mysql.xml tests/functional/ApiTest.php + - ./vendor/bin/phpunit -c tests/phpunit.functional.mysql.xml tests/functional/FeverApiTest.php after_failure: - cat apache_error.log diff --git a/docs/config.markdown b/docs/config.markdown index 62c12a2..1b3968c 100644 --- a/docs/config.markdown +++ b/docs/config.markdown @@ -12,7 +12,7 @@ To override them, rename the file `config.default.php` to `config.php`. Database configuration ---------------------- -By default, Miniflux uses Sqlite but Postgres and mysql are also supported. +By default, Miniflux uses Sqlite but Postgres and MySQL are also supported. ### Sqlite configuration @@ -87,11 +87,11 @@ define('FAVICON_URL_PATH', 'data/favicons'); // Database driver: "sqlite", "postgres", or "mysql" default is sqlite define('DB_DRIVER', 'sqlite'); -// Database connection parameters when Postgres or Mysql are used +// Database connection parameters when Postgres or MySQL are used define('DB_HOSTNAME', 'localhost'); define('DB_NAME', 'miniflux'); -define('DB_USERNAME', 'postgres'); -define('DB_PASSWORD', ''); +define('DB_USERNAME', 'my db user'); +define('DB_PASSWORD', 'my secret password'); // DB_FILENAME => database file when Sqlite is used define('DB_FILENAME', DATA_DIRECTORY.'/db.sqlite'); diff --git a/docs/installation.markdown b/docs/installation.markdown index 747b069..b0c62f1 100644 --- a/docs/installation.markdown +++ b/docs/installation.markdown @@ -27,7 +27,7 @@ Installation 1. `git clone https://github.com/miniflux/miniflux.git` 2. Go to the third step just above -By default, Miniflux uses Sqlite, if you would like to use Postgres instead you will have to modify your `config.php` file. +By default, Miniflux uses Sqlite, if you would like to use Postgres or MySQL instead you will have to modify your `config.php` file. Security -------- diff --git a/tests/ci/config.mysql.php b/tests/ci/config.mysql.php new file mode 100644 index 0000000..dc5f9e6 --- /dev/null +++ b/tests/ci/config.mysql.php @@ -0,0 +1,7 @@ +exec('DROP DATABASE '.DB_NAME); $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME); $pdo = null; + } else if (DB_DRIVER === 'mysql') { + $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD); + $stmt = $pdo->query("SELECT information_schema.processlist.id FROM information_schema.processlist WHERE information_schema.processlist.DB = '".DB_NAME."' AND id <> connection_id()"); + while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $pdo->exec('KILL '.$row['id']); + } + $pdo->exec('DROP DATABASE '.DB_NAME); + $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME); + $pdo = null; } else if (file_exists(DB_FILENAME)) { unlink(DB_FILENAME); } diff --git a/tests/phpunit.functional.mysql.xml b/tests/phpunit.functional.mysql.xml new file mode 100644 index 0000000..b5c6655 --- /dev/null +++ b/tests/phpunit.functional.mysql.xml @@ -0,0 +1,15 @@ + + + + functional + + + + + + + + + + + diff --git a/tests/phpunit.unit.mysql.xml b/tests/phpunit.unit.mysql.xml new file mode 100644 index 0000000..ba82901 --- /dev/null +++ b/tests/phpunit.unit.mysql.xml @@ -0,0 +1,13 @@ + + + + unit + + + + + + + + + diff --git a/tests/unit/BaseTest.php b/tests/unit/BaseTest.php index b4c47d7..c00063e 100644 --- a/tests/unit/BaseTest.php +++ b/tests/unit/BaseTest.php @@ -17,6 +17,11 @@ abstract class BaseTest extends PHPUnit_Framework_TestCase $pdo->exec('DROP DATABASE '.DB_NAME); $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME); $pdo = null; + } else 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.' WITH OWNER '.DB_USERNAME); + $pdo = null; } PicoDb\Database::setInstance('db', function () {