]> git.mxchange.org Git - friendica.git/commitdiff
Use MYSQL_* environment variables for tests
authorHypolite Petovan <mrpetovan@gmail.com>
Tue, 3 Jul 2018 12:26:44 +0000 (08:26 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Tue, 3 Jul 2018 12:26:44 +0000 (08:26 -0400)
- Prevent `.htconfig.php` override when present during tests.

.travis.yml
htconfig.php
tests/DatabaseTest.php

index 82b5a5d218bd3de32b17a142b8e22026263b1e5b..b722fe77f11bc52f2bb34b5217b26dcd7d2760a8 100644 (file)
@@ -10,11 +10,9 @@ php:
 services:
  - mysql
 env:
- - USER=travis DB=test
+ - MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USERNAME=travis MYSQL_PASSWORD= MYSQL_DATABASE=test
 
 install:
  - composer install
 before_script:
  - mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- # In order to avoid bin/worker.php warnings
- - touch .htconfig.php
index 0e838bd90d6e28a1d0e8ed87b719633e3b1d28d2..87c1301abd602526a4ba30d6288130c302c63f03 100644 (file)
@@ -23,17 +23,19 @@ $db_data = 'mysqldatabasename';
 
 // Use environment variables for mysql if they are set beforehand
 if (!empty(getenv('MYSQL_HOST'))
-       && !empty(getenv('MYSQL_PORT'))
        && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER')))
-       && !empty(getenv('MYSQL_PASSWORD'))
+       && !getenv('MYSQL_PASSWORD') === false
        && !empty(getenv('MYSQL_DATABASE'))) {
-       $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT');
+       $db_host = getenv('MYSQL_HOST');
+       if (!empty(getenv('MYSQL_PORT'))) {
+               $db_host .= ':' . getenv('MYSQL_PORT');
+       }
        if (!empty(getenv('MYSQL_USERNAME'))) {
                $db_user = getenv('MYSQL_USERNAME');
-       } elseif (!empty(getenv('MYSQL_USER'))) {
+       } else {
                $db_user = getenv('MYSQL_USER');
        }
-       $db_pass = getenv('MYSQL_PASSWORD');
+       $db_pass = (string) getenv('MYSQL_PASSWORD');
        $db_data = getenv('MYSQL_DATABASE');
 }
 
index 6edd45e575f257f3e584d8b907aca607bf20e3eb..b53d59161a5340e44c5096f57478db27ca25d540 100644 (file)
@@ -33,15 +33,13 @@ abstract class DatabaseTest extends TestCase
                $base_config_file_path = stream_resolve_include_path($base_config_file_name);
                $config_file_path = dirname($base_config_file_path) . DIRECTORY_SEPARATOR . $config_file_name;
 
-               $config_string = file_get_contents($base_config_file_path);
+               if (!file_exists($config_file_path)) {
+                       $config_string = file_get_contents($base_config_file_path);
 
-               $config_string = str_replace('die(', '// die(', $config_string);
-               $config_string = str_replace('your.mysqlhost.com', 'localhost', $config_string);
-               $config_string = str_replace('mysqlusername'     , getenv('USER'), $config_string);
-               $config_string = str_replace('mysqlpassword'     , getenv('PASS'), $config_string);
-               $config_string = str_replace('mysqldatabasename' , getenv('DB'), $config_string);
+                       $config_string = str_replace('die(', '// die(', $config_string);
 
-               file_put_contents($config_file_path, $config_string);
+                       file_put_contents($config_file_path, $config_string);
+               }
        }
 
        /**
@@ -58,7 +56,7 @@ abstract class DatabaseTest extends TestCase
        protected function getConnection()
        {
                if (!dba::$connected) {
-                       dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
+                       dba::connect(getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'), getenv('MYSQL_USERNAME'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE'));
 
                        if (dba::$connected) {
                                $app = get_app();