From 29692df109baf946d65e168dcbcac5601dbadbcd Mon Sep 17 00:00:00 2001 From: diosmosis <benaka@piwik.pro> Date: Mon, 6 Apr 2015 17:33:58 -0700 Subject: [PATCH] Fixing two more system test failures, including one caused by the static cache in Archive.php never being cleared, and the environment not existing in web archiving. --- core/Archive.php | 8 ++++++++ misc/cron/archive.php | 7 +++++-- tests/PHPUnit/Framework/Fixture.php | 2 ++ .../TwoVisitsWithCustomVariablesSegmentMatchNONETest.php | 9 +++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/Archive.php b/core/Archive.php index 5178718e73..161afb33ba 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -933,4 +933,12 @@ class Archive return $idArchivesByMonth; } + + /** + * @internal + */ + public static function clearStaticCache() + { + self::$cache = null; + } } diff --git a/misc/cron/archive.php b/misc/cron/archive.php index 2f0d97a523..a1923e01e4 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -64,14 +64,17 @@ if (isset($_SERVER['argv']) && Piwik\Console::isSupported()) { if (Piwik\Common::isPhpCliMode()) { // We can run the archive in CLI with `php-cgi` so we have to configure the container/logger // just like for CLI - $container = new \Piwik\Application\Environment('cli'); - $container->init(); + $environment = new \Piwik\Application\Environment('cli'); + $environment->init(); /** @var ConsoleHandler $consoleLogHandler */ $consoleLogHandler = StaticContainer::get('Symfony\Bridge\Monolog\Handler\ConsoleHandler'); $consoleLogHandler->setOutput(new ConsoleOutput(OutputInterface::VERBOSITY_VERBOSE)); } else { // HTTP request: logs needs to be dumped in the HTTP response (on top of existing log destinations) + $environment = new \Piwik\Application\Environment(null); + $environment->init(); + /** @var \Monolog\Logger $logger */ $logger = StaticContainer::get('Psr\Log\LoggerInterface'); $handler = new StreamHandler('php://output', Logger::INFO); diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index c9f6ba2f9d..04d63cdce9 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -10,6 +10,7 @@ namespace Piwik\Tests\Framework; use Piwik\Access; use Piwik\Application\Environment; use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider; +use Piwik\Archive; use Piwik\Cache\Backend\File; use Piwik\Cache as PiwikCache; use Piwik\Common; @@ -311,6 +312,7 @@ class Fixture extends \PHPUnit_Framework_Assert public function clearInMemoryCaches() { + Archive::clearStaticCache(); DataTableManager::getInstance()->deleteAll(); Option::clearCache(); Site::clearCache(); diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php index 9cbc606a1f..4ab45a24fc 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php @@ -26,22 +26,23 @@ class TwoVisitsWithCustomVariablesSegmentMatchNONETest extends SystemTestCase */ public function testApi($api, $params) { + if (!array_key_exists('segment', $params)) { + $params['segment'] = $this->getSegmentToTest(); // this method can access the DB, so we get it here instead of the data provider + } + $this->runApiTests($api, $params); } public function getApiForTesting() { // we will test all segments from all plugins - Fixture::loadAllPlugins(); - $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables'); return array( array($apiToCall, array('idSite' => 'all', 'date' => self::$fixture->dateTime, 'periods' => array('day', 'week'), - 'setDateLastN' => true, - 'segment' => $this->getSegmentToTest())) + 'setDateLastN' => true)) ); } -- GitLab