Skip to content
Extraits de code Groupes Projets
Valider 39a2c9c7 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

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
parent 54b4d65e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -29,7 +29,7 @@ schema = Mysql ...@@ -29,7 +29,7 @@ schema = Mysql
[database_tests] [database_tests]
host = localhost host = localhost
username = root username = "@USERNAME@"
password = password =
dbname = piwik_tests dbname = piwik_tests
tables_prefix = piwiktests_ tables_prefix = piwiktests_
......
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Updates;
use Piwik\Config;
use Piwik\Development;
use Piwik\Updates;
class Updates_2_11_1_b3 extends Updates
{
/**
* Here you can define any action that should be performed during the update. For instance executing SQL statements,
* renaming config entries, updating files, etc.
*/
static function update()
{
if (!Development::isEnabled()) {
return;
}
$config = Config::getInstance();
$dbTests = $config->database_tests;
if ($dbTests['username'] === '@USERNAME@') {
$dbTests['username'] = 'root';
}
$config->database_tests = $dbTests;
$config->forceSave();
}
}
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
use Piwik\Container\StaticContainer; use Piwik\Container\StaticContainer;
use Piwik\Http; use Piwik\Http;
use Piwik\Tests\Framework\Fixture;
use Piwik\Intl\Locale; use Piwik\Intl\Locale;
use Piwik\Config;
use Piwik\SettingsPiwik;
define('PIWIK_TEST_MODE', true); define('PIWIK_TEST_MODE', true);
define('PIWIK_PRINT_ERROR_BACKTRACE', false); define('PIWIK_PRINT_ERROR_BACKTRACE', false);
...@@ -60,9 +61,9 @@ foreach($fixturesToLoad as $fixturePath) { ...@@ -60,9 +61,9 @@ foreach($fixturesToLoad as $fixturePath) {
Locale::setDefaultLocale(); Locale::setDefaultLocale();
function prepareServerVariables() function prepareServerVariables(Config $config)
{ {
$testConfig = \Piwik\Config::getInstance()->tests; $testConfig = $config->tests;
if ('@REQUEST_URI@' === $testConfig['request_uri']) { if ('@REQUEST_URI@' === $testConfig['request_uri']) {
// config not done yet, if Piwik is installed we can automatically configure request_uri and http_host // config not done yet, if Piwik is installed we can automatically configure request_uri and http_host
...@@ -72,8 +73,8 @@ function prepareServerVariables() ...@@ -72,8 +73,8 @@ function prepareServerVariables()
$parsedUrl = parse_url($url); $parsedUrl = parse_url($url);
$testConfig['request_uri'] = $parsedUrl['path']; $testConfig['request_uri'] = $parsedUrl['path'];
$testConfig['http_host'] = $parsedUrl['host']; $testConfig['http_host'] = $parsedUrl['host'];
\Piwik\Config::getInstance()->tests = $testConfig; $config->tests = $testConfig;
\Piwik\Config::getInstance()->forceSave(); $config->forceSave();
} }
} }
...@@ -82,13 +83,41 @@ function prepareServerVariables() ...@@ -82,13 +83,41 @@ function prepareServerVariables()
$_SERVER['REMOTE_ADDR'] = $testConfig['remote_addr']; $_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! $testDb['tables_prefix'] = ''; // tables_prefix has to be empty for UI tests
if (empty($_SERVER['argv']) || !in_array('UnitTests', $_SERVER['argv'])) {
checkPiwikSetupForTests(); $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() function checkPiwikSetupForTests()
{ {
if (empty($_SERVER['REQUEST_URI']) if (empty($_SERVER['REQUEST_URI'])
...@@ -108,22 +137,4 @@ Try again."; ...@@ -108,22 +137,4 @@ Try again.";
exit(1); 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 &#039;piwik_tests.option&#039; doesn&#039;t exist') !== false
|| strpos($response, 'Table &#039;piwik_tests.piwiktests_option&#039; doesn&#039;t exist') !== false
|| strpos($response, 'Unknown database &#039;piwik_tests&#039;') !== false
|| strpos($response, '<title>Piwik &rsaquo; Update</title>') !== false
) {
return;
}
throw new Exception(sprintf(
"Piwik should be running at %s but this URL returned an unexpected response: '%s'",
$url,
$response
));
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter