diff options
author | diosmosis <benaka@piwik.pro> | 2015-06-12 04:01:47 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-06-12 05:14:32 +0300 |
commit | a73f710ff43ddad326292407fa952c532d2a363a (patch) | |
tree | 29b573154fee9f12a273aa13c1f7bba6a6b5467d /tests | |
parent | bb183ede23d1af1d26468582d01bb679ce76e41e (diff) |
Load plugins in tests automatically through testing environment manipulation, instead of through a method in Fixture. Allows plugin environment configs to be loaded during tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Framework/Fixture.php | 37 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/TestingEnvironmentManipulator.php | 53 |
2 files changed, 57 insertions, 33 deletions
diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index b2277b7d31..0cbd4e9394 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -176,6 +176,8 @@ class Fixture extends \PHPUnit_Framework_Assert public function performSetUp($setupEnvironmentOnly = false) { + TestingEnvironmentManipulator::$extraPluginsToLoad = $this->extraPluginsToLoad; + $this->createEnvironmentInstance(); try { @@ -345,41 +347,10 @@ class Fixture extends \PHPUnit_Framework_Assert // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object } - public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) + public static function loadAllPlugins(TestingEnvironmentVariables $testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) { - if (empty($testEnvironment)) { - $testEnvironment = new TestingEnvironmentVariables(); - } - DbHelper::createTables(); - $pluginsManager = Manager::getInstance(); - - $plugins = $testEnvironment->getCoreAndSupportedPlugins(); - - // make sure the plugin that executed this method is included in the plugins to load - $extraPlugins = array_merge($extraPluginsToLoad, array( - Plugin::getPluginNameFromBacktrace(debug_backtrace()), - Plugin::getPluginNameFromNamespace($testCaseClass), - Plugin::getPluginNameFromNamespace(get_called_class()) - )); - foreach ($extraPlugins as $pluginName) { - if (empty($pluginName)) { - continue; - } - - if (in_array($pluginName, $plugins)) { - continue; - } - - $plugins[] = $pluginName; - if ($testEnvironment) { - $testEnvironment->pluginsToLoad = array_merge($testEnvironment->pluginsToLoad ?: array(), array($pluginName)); - } - } - - Log::debug("Plugins to load during tests: " . implode(', ', $plugins)); - - $pluginsManager->loadPlugins($plugins); + Plugin\Manager::getInstance()->loadActivatedPlugins(); } public static function installAndActivatePlugins() diff --git a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php index 67aa6560b6..62098c9ae4 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php @@ -10,8 +10,26 @@ namespace Piwik\Tests\Framework; use Piwik\Application\EnvironmentManipulator; use Piwik\Application\Kernel\GlobalSettingsProvider; +use Piwik\Application\Kernel\PluginList; use Piwik\DbHelper; use Piwik\Option; +use Piwik\Plugin; + +class FakePluginList extends PluginList +{ + private $plugins; + + public function __construct(GlobalSettingsProvider $globalSettingsProvider, $plugins) + { + parent::__construct($globalSettingsProvider); + $this->plugins = $plugins; + } + + public function getActivatedPlugins() + { + return $this->plugins; + } +} /** * Manipulates an environment for tests. @@ -19,6 +37,11 @@ use Piwik\Option; class TestingEnvironmentManipulator implements EnvironmentManipulator { /** + * @var string[] + */ + public static $extraPluginsToLoad = array(); + + /** * @var TestingEnvironmentVariables */ private $vars; @@ -36,6 +59,11 @@ class TestingEnvironmentManipulator implements EnvironmentManipulator return new GlobalSettingsProvider($this->vars->configFileGlobal, $this->vars->configFileLocal, $this->vars->configFileCommon); } + public function makePluginList(GlobalSettingsProvider $globalSettingsProvider) + { + return new FakePluginList($globalSettingsProvider, $this->getPluginsToLoadDuringTest()); + } + public function beforeContainerCreated() { if ($this->vars->queryParamOverride) { @@ -134,4 +162,29 @@ class TestingEnvironmentManipulator implements EnvironmentManipulator { return array('test'); } + + private function getPluginsToLoadDuringTest() + { + $plugins = $this->vars->getCoreAndSupportedPlugins(); + + // make sure the plugin that executed this method is included in the plugins to load + $extraPlugins = array_merge(self::$extraPluginsToLoad, array( + Plugin::getPluginNameFromBacktrace(debug_backtrace()), + Plugin::getPluginNameFromNamespace($this->vars->testCaseClass), + Plugin::getPluginNameFromNamespace(get_called_class()) + )); + foreach ($extraPlugins as $pluginName) { + if (empty($pluginName)) { + continue; + } + + if (in_array($pluginName, $plugins)) { + continue; + } + + $plugins[] = $pluginName; + } + + return $plugins; + } }
\ No newline at end of file |