Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-04-06 07:49:37 +0300
committerdiosmosis <benaka@piwik.pro>2015-04-06 07:49:37 +0300
commitd01ac2028a7877171c7f5a868b2ff2d7ccff14ac (patch)
tree0a4e678ca7e342a7230a7a96f8e2b9a99d48ed37
parent59da292a3505a740fd0189e7f1d0f9231edeeb12 (diff)
Make IniSettingsProvider a singleton in order to make sure IniFileChain is shared (again, regressed in a previous commit), and fixed many tests. Changed CacheTest from integration to unit.
-rw-r--r--core/Application/Environment.php4
-rw-r--r--core/Application/Kernel/GlobalSettingsProvider/IniSettingsProvider.php21
-rw-r--r--core/Config.php6
-rw-r--r--plugins/CoreHome/tests/Integration/Column/UserIdTest.php1
-rw-r--r--plugins/Monolog/Test/Integration/LogTest.php12
-rw-r--r--tests/PHPUnit/Framework/Fixture.php3
-rw-r--r--tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php3
-rwxr-xr-xtests/PHPUnit/Framework/TestCase/UnitTestCase.php11
-rw-r--r--tests/PHPUnit/Unit/CacheTest.php (renamed from tests/PHPUnit/Integration/CacheTest.php)19
-rw-r--r--tests/PHPUnit/Unit/ConfigTest.php10
-rw-r--r--tests/resources/staticFileServer.php3
11 files changed, 52 insertions, 41 deletions
diff --git a/core/Application/Environment.php b/core/Application/Environment.php
index 08cdf9cc17..ac198ea295 100644
--- a/core/Application/Environment.php
+++ b/core/Application/Environment.php
@@ -59,7 +59,7 @@ class Environment
StaticContainer::set($this->container);
- Piwik::postEvent('Environment.bootstrapped');
+ Piwik::postEvent('Environment.bootstrapped'); // this event should be removed eventually
}
public function getContainer()
@@ -103,7 +103,7 @@ class Environment
protected function getGlobalSettings()
{
- return new IniSettingsProvider();
+ return IniSettingsProvider::getSingletonInstance();
}
protected function getPluginList()
diff --git a/core/Application/Kernel/GlobalSettingsProvider/IniSettingsProvider.php b/core/Application/Kernel/GlobalSettingsProvider/IniSettingsProvider.php
index 72bc73e6a6..6aa84d1cb8 100644
--- a/core/Application/Kernel/GlobalSettingsProvider/IniSettingsProvider.php
+++ b/core/Application/Kernel/GlobalSettingsProvider/IniSettingsProvider.php
@@ -23,11 +23,6 @@ class IniSettingsProvider implements \Piwik\Application\Kernel\GlobalSettingsPro
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
- $this->reload($pathGlobal, $pathLocal, $pathCommon);
- }
-
- public function reload($pathGlobal = null, $pathLocal = null, $pathCommon = null)
- {
$this->iniFileChain = IniFileChainFactory::get($pathGlobal, $pathLocal, $pathCommon); // TODO: move IniFileChainFactory logic to here.
}
@@ -46,4 +41,20 @@ class IniSettingsProvider implements \Piwik\Application\Kernel\GlobalSettingsPro
{
return $this->iniFileChain;
}
+
+ private static $instance = null;
+
+ public static function getSingletonInstance($pathGlobal = null, $pathLocal = null, $pathCommon = null)
+ {
+ if (self::$instance === null) {
+ self::$instance = new IniSettingsProvider($pathGlobal, $pathLocal, $pathCommon);
+ }
+
+ return self::$instance;
+ }
+
+ public static function unsetSingletonInstance()
+ {
+ self::$instance = null;
+ }
} \ No newline at end of file
diff --git a/core/Config.php b/core/Config.php
index 34810f4472..d4a0f7f40c 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -76,11 +76,7 @@ class Config extends Singleton
$this->pathCommon = $pathCommon ?: self::getCommonConfigPath();
$this->pathLocal = $pathLocal ?: self::getLocalConfigPath();
- /** @var IniSettingsProvider $settings */
- $settings = StaticContainer::get('Piwik\Application\Kernel\GlobalSettingsProvider');
- $settings->reload($pathGlobal, $pathLocal, $pathCommon);
-
- $this->settings = $settings->getIniFileChain();
+ $this->settings = IniSettingsProvider::getSingletonInstance($pathGlobal, $pathLocal, $pathCommon)->getIniFileChain();
}
/**
diff --git a/plugins/CoreHome/tests/Integration/Column/UserIdTest.php b/plugins/CoreHome/tests/Integration/Column/UserIdTest.php
index f2ca415b5a..4d4bcf10bf 100644
--- a/plugins/CoreHome/tests/Integration/Column/UserIdTest.php
+++ b/plugins/CoreHome/tests/Integration/Column/UserIdTest.php
@@ -12,6 +12,7 @@ use Piwik\Access;
use Piwik\Cache;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Db;
+use Piwik\Plugin\Manager;
use Piwik\Plugins\CoreHome\Columns\UserId;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
diff --git a/plugins/Monolog/Test/Integration/LogTest.php b/plugins/Monolog/Test/Integration/LogTest.php
index 2975015301..50de71bf2e 100644
--- a/plugins/Monolog/Test/Integration/LogTest.php
+++ b/plugins/Monolog/Test/Integration/LogTest.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\Monolog\Test\Integration;
use Exception;
+use Piwik\Application\Environment;
use Piwik\Common;
use Piwik\Config;
use Piwik\Container\ContainerFactory;
@@ -39,9 +40,9 @@ class LogTest extends IntegrationTestCase
parent::setUp();
// Create the container in the normal environment (because in tests logging is disabled)
- $containerFactory = new ContainerFactory();
- $container = $containerFactory->create();
- StaticContainer::set($container);
+ $environment = new Environment(null);
+ $environment->init();
+
Log::unsetInstance();
Config::getInstance()->log['string_message_format'] = self::STRING_MESSAGE_FORMAT;
@@ -53,13 +54,12 @@ class LogTest extends IntegrationTestCase
public function tearDown()
{
- parent::tearDown();
-
- StaticContainer::clearContainer();
Log::unsetInstance();
@unlink(self::getLogFileLocation());
Log::$debugBacktraceForTests = null;
+
+ parent::tearDown();
}
/**
diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php
index 82276e856b..866f13b7cb 100644
--- a/tests/PHPUnit/Framework/Fixture.php
+++ b/tests/PHPUnit/Framework/Fixture.php
@@ -9,6 +9,7 @@ namespace Piwik\Tests\Framework;
use Piwik\Access;
use Piwik\Application\Environment;
+use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Cache\Backend\File;
use Piwik\Cache as PiwikCache;
use Piwik\Common;
@@ -148,6 +149,8 @@ class Fixture extends \PHPUnit_Framework_Assert
public function performSetUp($setupEnvironmentOnly = false)
{
+ IniSettingsProvider::unsetSingletonInstance();
+
$this->piwikEnvironment = new Environment('test');
$this->piwikEnvironment->init();
diff --git a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php
index b132465431..7a1e3b4375 100644
--- a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php
+++ b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php
@@ -13,7 +13,6 @@ use Piwik\Db;
use Piwik\Tests\Framework\Fixture;
use Piwik\Cache as PiwikCache;
use Piwik\Tests\Framework\Mock\TestConfig;
-use Piwik\Translate;
/**
* Tests extending IntegrationTestCase are much slower to run: the setUp will
@@ -75,8 +74,6 @@ abstract class IntegrationTestCase extends SystemTestCase
{
parent::setUp();
- Config::setSingletonInstance(new TestConfig());
-
if (!empty(self::$tableData)) {
self::restoreDbTables(self::$tableData);
}
diff --git a/tests/PHPUnit/Framework/TestCase/UnitTestCase.php b/tests/PHPUnit/Framework/TestCase/UnitTestCase.php
index 69347c99c7..3d9f8e660d 100755
--- a/tests/PHPUnit/Framework/TestCase/UnitTestCase.php
+++ b/tests/PHPUnit/Framework/TestCase/UnitTestCase.php
@@ -9,6 +9,7 @@
namespace Piwik\Tests\Framework\TestCase;
use Piwik\Application\Environment;
+use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Container\StaticContainer;
use Piwik\EventDispatcher;
use Piwik\Tests\Framework\Mock\File;
@@ -23,13 +24,15 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase
/**
* @var Environment
*/
- private $environment;
+ protected $environment;
public function setUp()
{
parent::setUp();
- $this->environment = new Environment('test', $this->provideContainerConfig());
+ IniSettingsProvider::unsetSingletonInstance();
+
+ $this->environment = new Environment('test', $this->provideContainerConfig(), $postBootstrappedEvent = false);
$this->environment->init();
File::reset();
@@ -40,11 +43,11 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase
{
File::reset();
- StaticContainer::clearContainer();
+ IniSettingsProvider::unsetSingletonInstance();
// make sure the global container exists for the next test case that is executed (since logging can be done
// before a test sets up an environment)
- $nextTestEnviornment = new Environment('test');
+ $nextTestEnviornment = new Environment('test', array(), $postBootstrappedEvent = false);
$nextTestEnviornment->init();
parent::tearDown();
diff --git a/tests/PHPUnit/Integration/CacheTest.php b/tests/PHPUnit/Unit/CacheTest.php
index 894a6e4695..24ec02c9b8 100644
--- a/tests/PHPUnit/Integration/CacheTest.php
+++ b/tests/PHPUnit/Unit/CacheTest.php
@@ -6,27 +6,17 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Tests\Integration;
+namespace Piwik\Tests\Unit;
use Piwik\Cache;
-use Piwik\Container\StaticContainer;
use Piwik\Piwik;
-use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
-use Piwik\Translate;
+use Piwik\Tests\Framework\TestCase\UnitTestCase;
/**
* @group Cache
*/
-class CacheTest extends IntegrationTestCase
+class CacheTest extends UnitTestCase
{
- public function setUp()
- {
- }
-
- public function tearDown()
- {
- }
-
public function test_getLazyCache_shouldCreateAnInstanceOfLazy()
{
$cache = Cache::getLazyCache();
@@ -59,13 +49,12 @@ class CacheTest extends IntegrationTestCase
public function test_getEagerCache_shouldPersistOnceEventWasTriggered()
{
- StaticContainer::clearContainer();
$storageId = 'eagercache-test-ui';
$cache = Cache::getEagerCache();
$cache->save('test', 'mycontent'); // make sure something was changed, otherwise it won't save anything
/** @var \Piwik\Cache\Backend $backend */
- $backend = StaticContainer::get('Piwik\Cache\Backend');
+ $backend = $this->environment->get('Piwik\Cache\Backend');
$this->assertFalse($backend->doContains($storageId));
Piwik::postEvent('Request.dispatch.end'); // should trigger save
diff --git a/tests/PHPUnit/Unit/ConfigTest.php b/tests/PHPUnit/Unit/ConfigTest.php
index 030144737b..b609928ec7 100644
--- a/tests/PHPUnit/Unit/ConfigTest.php
+++ b/tests/PHPUnit/Unit/ConfigTest.php
@@ -9,6 +9,7 @@
namespace Piwik\Tests\Unit;
use PHPUnit_Framework_TestCase;
+use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Config;
use Piwik\Tests\Framework\Mock\TestConfig;
@@ -43,8 +44,15 @@ class DumpConfigTestMockConfig extends Config
/**
* @group Core
*/
-class ConfigTest extends PHPUnit_Framework_TestCase
+class ConfigTest extends \PHPUnit_Framework_TestCase
{
+ public function setUp()
+ {
+ parent::setUp();
+
+ IniSettingsProvider::unsetSingletonInstance();
+ }
+
public function testUserConfigOverwritesSectionGlobalConfigValue()
{
$userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
diff --git a/tests/resources/staticFileServer.php b/tests/resources/staticFileServer.php
index bf26da55f4..696acebdcf 100644
--- a/tests/resources/staticFileServer.php
+++ b/tests/resources/staticFileServer.php
@@ -56,6 +56,9 @@ if ($staticFileServerMode === "") {
SRV_MODE_REQUEST_VAR . " must be provided.");
}
+$environment = new \Piwik\Application\Environment(null);
+$environment->init();
+
switch ($staticFileServerMode) {
// The static file server calls Piwik::serverStaticFile with a null file
case NULL_FILE_SRV_MODE: