diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-02-20 02:13:37 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-02-23 04:30:06 +0300 |
commit | 39a2c9c7237f2cd62c0949ac77c5e8673e9d3963 (patch) | |
tree | 69fd99a276adba603763441ea73afb9a98ce8be0 /tests/PHPUnit/bootstrap.php | |
parent | 54b4d65e0c164cc803dc4d4ad420ce6deb98f86d (diff) |
fixes #6635 automatically configure database_tests config for developers when running tests.
I also replaced the check that does a request against Piwik to check
whether it is installed with `SettingsPiwik::isInstalled()` as discussed
recently
Diffstat (limited to 'tests/PHPUnit/bootstrap.php')
-rw-r--r-- | tests/PHPUnit/bootstrap.php | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index 3a9cf799db..5a7eb7bce2 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -2,8 +2,9 @@ use Piwik\Container\StaticContainer; use Piwik\Http; -use Piwik\Tests\Framework\Fixture; use Piwik\Intl\Locale; +use Piwik\Config; +use Piwik\SettingsPiwik; define('PIWIK_TEST_MODE', true); define('PIWIK_PRINT_ERROR_BACKTRACE', false); @@ -60,9 +61,9 @@ foreach($fixturesToLoad as $fixturePath) { Locale::setDefaultLocale(); -function prepareServerVariables() +function prepareServerVariables(Config $config) { - $testConfig = \Piwik\Config::getInstance()->tests; + $testConfig = $config->tests; if ('@REQUEST_URI@' === $testConfig['request_uri']) { // config not done yet, if Piwik is installed we can automatically configure request_uri and http_host @@ -72,8 +73,8 @@ function prepareServerVariables() $parsedUrl = parse_url($url); $testConfig['request_uri'] = $parsedUrl['path']; $testConfig['http_host'] = $parsedUrl['host']; - \Piwik\Config::getInstance()->tests = $testConfig; - \Piwik\Config::getInstance()->forceSave(); + $config->tests = $testConfig; + $config->forceSave(); } } @@ -82,13 +83,41 @@ function prepareServerVariables() $_SERVER['REMOTE_ADDR'] = $testConfig['remote_addr']; } -prepareServerVariables(); +function prepareTestDatabaseConfig(Config $config) +{ + $testDb = $config->database_tests; + + if ('@USERNAME@' !== $testDb['username']) { + return; // testDb is already configured, we do not want to overwrite any existing settings. + } + + $db = $config->database; + $testDb['username'] = $db['username']; + + if (empty($testDb['password'])) { + $testDb['password'] = $db['password']; + } + + if (empty($testDb['host'])) { + $testDb['host'] = $db['host']; + } -// General requirement checks & help: a webserver must be running for tests to work if not running UnitTests! -if (empty($_SERVER['argv']) || !in_array('UnitTests', $_SERVER['argv'])) { - checkPiwikSetupForTests(); + $testDb['tables_prefix'] = ''; // tables_prefix has to be empty for UI tests + + $config->database_tests = $testDb; + $config->forceSave(); +} + +if (!SettingsPiwik::isPiwikInstalled()) { + throw new Exception('Piwik needs to be installed in order to run the tests'); } +$config = Config::getInstance(); +$config->init(); +prepareServerVariables($config); +prepareTestDatabaseConfig($config); +checkPiwikSetupForTests(); + function checkPiwikSetupForTests() { if (empty($_SERVER['REQUEST_URI']) @@ -108,22 +137,4 @@ Try again."; exit(1); } - $url = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php?module=TestRunner&action=check'; - $response = Http::sendHttpRequestBy('curl', $url, 5); - - if ($response === 'OK' - // The SQL error is for Travis... - || strpos($response, 'Table 'piwik_tests.option' doesn't exist') !== false - || strpos($response, 'Table 'piwik_tests.piwiktests_option' doesn't exist') !== false - || strpos($response, 'Unknown database 'piwik_tests'') !== false - || strpos($response, '<title>Piwik › Update</title>') !== false - ) { - return; - } - - throw new Exception(sprintf( - "Piwik should be running at %s but this URL returned an unexpected response: '%s'", - $url, - $response - )); } |