diff options
author | diosmosis <benaka@piwik.pro> | 2015-04-06 07:49:37 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-04-06 07:49:37 +0300 |
commit | d01ac2028a7877171c7f5a868b2ff2d7ccff14ac (patch) | |
tree | 0a4e678ca7e342a7230a7a96f8e2b9a99d48ed37 /tests | |
parent | 59da292a3505a740fd0189e7f1d0f9231edeeb12 (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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Framework/Fixture.php | 3 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php | 3 | ||||
-rwxr-xr-x | tests/PHPUnit/Framework/TestCase/UnitTestCase.php | 11 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/CacheTest.php (renamed from tests/PHPUnit/Integration/CacheTest.php) | 19 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/ConfigTest.php | 10 | ||||
-rw-r--r-- | tests/resources/staticFileServer.php | 3 |
6 files changed, 26 insertions, 23 deletions
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: |