Skip to content
Extraits de code Groupes Projets
Valider fca0ce78 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Fixing ArchiveWebTest, now that test.php is used (which disables the logger),...

Fixing ArchiveWebTest, now that test.php is used (which disables the logger), we must enable it in a test class override method, since this test checks the log output.

Fixing LogTest now that NullLogger is used for test environment setup.

Make sure translations are loaded in EnvironmentValidationTest.php.

Make sure the logger is enabled for ArchiveCronTest.
parent ff60b6c7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -12,7 +12,6 @@ use Exception; ...@@ -12,7 +12,6 @@ use Exception;
use Piwik\Application\Environment; use Piwik\Application\Environment;
use Piwik\Common; use Piwik\Common;
use Piwik\Config; use Piwik\Config;
use Piwik\Container\ContainerFactory;
use Piwik\Container\StaticContainer; use Piwik\Container\StaticContainer;
use Piwik\Db; use Piwik\Db;
use Piwik\Log; use Piwik\Log;
...@@ -29,7 +28,7 @@ class LogTest extends IntegrationTestCase ...@@ -29,7 +28,7 @@ class LogTest extends IntegrationTestCase
const STRING_MESSAGE_FORMAT = '[%tag%] %message%'; const STRING_MESSAGE_FORMAT = '[%tag%] %message%';
const STRING_MESSAGE_FORMAT_SPRINTF = "[%s] %s"; const STRING_MESSAGE_FORMAT_SPRINTF = "[%s] %s";
public static $expectedExceptionOutput = '[Monolog] LogTest.php(120): dummy error message public static $expectedExceptionOutput = '[Monolog] LogTest.php(112): dummy error message
dummy backtrace'; dummy backtrace';
public static $expectedErrorOutput = '[Monolog] dummyerrorfile.php(145): Unknown error (102) - dummy error string public static $expectedErrorOutput = '[Monolog] dummyerrorfile.php(145): Unknown error (102) - dummy error string
...@@ -39,15 +38,8 @@ class LogTest extends IntegrationTestCase ...@@ -39,15 +38,8 @@ class LogTest extends IntegrationTestCase
{ {
parent::setUp(); parent::setUp();
// Create the container in the normal environment (because in tests logging is disabled)
$environment = new Environment(null);
$environment->init();
Log::unsetInstance(); Log::unsetInstance();
Config::getInstance()->log['string_message_format'] = self::STRING_MESSAGE_FORMAT;
Config::getInstance()->log['logger_file_path'] = self::getLogFileLocation();
Config::getInstance()->log['log_level'] = Log::INFO;
@unlink(self::getLogFileLocation()); @unlink(self::getLogFileLocation());
Log::$debugBacktraceForTests = "dummy backtrace"; Log::$debugBacktraceForTests = "dummy backtrace";
} }
...@@ -78,7 +70,7 @@ class LogTest extends IntegrationTestCase ...@@ -78,7 +70,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingWorksWhenMessageIsString($backend) public function testLoggingWorksWhenMessageIsString($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
Log::warning(self::TESTMESSAGE); Log::warning(self::TESTMESSAGE);
...@@ -90,7 +82,7 @@ class LogTest extends IntegrationTestCase ...@@ -90,7 +82,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingWorksWhenMessageIsSprintfString($backend) public function testLoggingWorksWhenMessageIsSprintfString($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
Log::warning(self::TESTMESSAGE, " subst "); Log::warning(self::TESTMESSAGE, " subst ");
...@@ -102,7 +94,7 @@ class LogTest extends IntegrationTestCase ...@@ -102,7 +94,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingWorksWhenMessageIsError($backend) public function testLoggingWorksWhenMessageIsError($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
$error = new \ErrorException("dummy error string", 0, 102, "dummyerrorfile.php", 145); $error = new \ErrorException("dummy error string", 0, 102, "dummyerrorfile.php", 145);
Log::error($error); Log::error($error);
...@@ -115,7 +107,7 @@ class LogTest extends IntegrationTestCase ...@@ -115,7 +107,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingWorksWhenMessageIsException($backend) public function testLoggingWorksWhenMessageIsException($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
$exception = new Exception("dummy error message"); $exception = new Exception("dummy error message");
Log::error($exception); Log::error($exception);
...@@ -128,7 +120,7 @@ class LogTest extends IntegrationTestCase ...@@ -128,7 +120,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingCorrectlyIdentifiesPlugin($backend) public function testLoggingCorrectlyIdentifiesPlugin($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
LoggerWrapper::doLog(self::TESTMESSAGE); LoggerWrapper::doLog(self::TESTMESSAGE);
...@@ -140,8 +132,7 @@ class LogTest extends IntegrationTestCase ...@@ -140,8 +132,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLogMessagesIgnoredWhenNotWithinLevel($backend) public function testLogMessagesIgnoredWhenNotWithinLevel($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend, 'ERROR');
Config::getInstance()->log['log_level'] = 'ERROR';
Log::info(self::TESTMESSAGE); Log::info(self::TESTMESSAGE);
...@@ -153,7 +144,7 @@ class LogTest extends IntegrationTestCase ...@@ -153,7 +144,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLogMessagesAreTrimmed($backend) public function testLogMessagesAreTrimmed($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
LoggerWrapper::doLog(" \n ".self::TESTMESSAGE."\n\n\n \n"); LoggerWrapper::doLog(" \n ".self::TESTMESSAGE."\n\n\n \n");
...@@ -165,7 +156,7 @@ class LogTest extends IntegrationTestCase ...@@ -165,7 +156,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testTokenAuthIsRemoved($backend) public function testTokenAuthIsRemoved($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
Log::error('token_auth=9b1cefc915ff6180071fb7dcd13ec5a4'); Log::error('token_auth=9b1cefc915ff6180071fb7dcd13ec5a4');
...@@ -179,8 +170,7 @@ class LogTest extends IntegrationTestCase ...@@ -179,8 +170,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testNoInfiniteLoopWhenLoggingToDatabase() public function testNoInfiniteLoopWhenLoggingToDatabase()
{ {
Config::getInstance()->log['log_writers'] = array('database'); $this->recreateLogSingleton('database');
Config::getInstance()->log['log_level'] = 'DEBUG';
Log::info(self::TESTMESSAGE); Log::info(self::TESTMESSAGE);
...@@ -192,7 +182,7 @@ class LogTest extends IntegrationTestCase ...@@ -192,7 +182,7 @@ class LogTest extends IntegrationTestCase
*/ */
public function testLoggingNonString($backend) public function testLoggingNonString($backend)
{ {
Config::getInstance()->log['log_writers'] = array($backend); $this->recreateLogSingleton($backend);
Log::warning(123); Log::warning(123);
...@@ -258,4 +248,27 @@ class LogTest extends IntegrationTestCase ...@@ -258,4 +248,27 @@ class LogTest extends IntegrationTestCase
{ {
return StaticContainer::get('path.tmp') . '/logs/piwik.test.log'; return StaticContainer::get('path.tmp') . '/logs/piwik.test.log';
} }
public function provideContainerConfig()
{
return array(
'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger')
);
}
private function recreateLogSingleton($backend, $level = 'INFO')
{
$newEnv = new Environment('test', array(
'ini.log.log_writers' => array($backend),
'ini.log.log_level' => $level,
'ini.log.string_message_format' => self::STRING_MESSAGE_FORMAT,
'ini.log.logger_file_path' => self::getLogFileLocation(),
'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger')
));
$newEnv->init();
$newMonologLogger = $newEnv->getContainer()->make('Psr\Log\LoggerInterface');
$oldLogger = new Log($newMonologLogger);
Log::setSingletonInstance($oldLogger);
}
} }
...@@ -158,6 +158,13 @@ class ArchiveCronTest extends SystemTestCase ...@@ -158,6 +158,13 @@ class ArchiveCronTest extends SystemTestCase
$this->comparisonFailures[] = $ex; $this->comparisonFailures[] = $ex;
} }
} }
public static function provideContainerConfigBeforeClass()
{
return array(
'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger')
);
}
} }
ArchiveCronTest::$fixture = new ManySitesImportedLogs(); ArchiveCronTest::$fixture = new ManySitesImportedLogs();
......
...@@ -96,6 +96,13 @@ class ArchiveWebTest extends SystemTestCase ...@@ -96,6 +96,13 @@ class ArchiveWebTest extends SystemTestCase
return array($returnCode, $output); return array($returnCode, $output);
} }
public static function provideContainerConfigBeforeClass()
{
return array(
'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger')
);
}
} }
ArchiveWebTest::$fixture = new ManySitesImportedLogs(); ArchiveWebTest::$fixture = new ManySitesImportedLogs();
......
...@@ -34,6 +34,7 @@ class EnvironmentValidationTest extends SystemTestCase ...@@ -34,6 +34,7 @@ class EnvironmentValidationTest extends SystemTestCase
$testingEnvironment->configFileGlobal = null; $testingEnvironment->configFileGlobal = null;
$testingEnvironment->configFileLocal = null; $testingEnvironment->configFileLocal = null;
$testingEnvironment->configFileCommon = null; $testingEnvironment->configFileCommon = null;
$testingEnvironment->loadRealTranslations = true;
$testingEnvironment->save(); $testingEnvironment->save();
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter