Skip to content

Commit

Permalink
Make TEstingEnvironmentManipulator override the global settings provi…
Browse files Browse the repository at this point in the history
…der ONLY if were custom paths used. This allows other Environment classes to provide their own custom provider, w/o it being overridden by tests. Also when getting DI overrides from a fixture, use the fixture that is configured by the test class, so any fixture properties will be correctly initialized.
  • Loading branch information
diosmosis committed Jun 20, 2015
1 parent 1b0671c commit 49311eb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
10 changes: 6 additions & 4 deletions core/Application/Environment.php
Expand Up @@ -138,8 +138,10 @@ private function createContainer()
protected function getGlobalSettingsCached()
{
if ($this->globalSettingsProvider === null) {
$globalSettingsProvider = $this->getGlobalSettingsProviderOverride();
$this->globalSettingsProvider = $globalSettingsProvider ?: $this->getGlobalSettings();
$original = $this->getGlobalSettings();
$globalSettingsProvider = $this->getGlobalSettingsProviderOverride($original);

$this->globalSettingsProvider = $globalSettingsProvider ?: $original;
}
return $this->globalSettingsProvider;
}
Expand Down Expand Up @@ -192,10 +194,10 @@ public static function setGlobalEnvironmentManipulator(EnvironmentManipulator $m
self::$globalEnvironmentManipulator = $manipulator;
}

private function getGlobalSettingsProviderOverride()
private function getGlobalSettingsProviderOverride(GlobalSettingsProvider $original)
{
if (self::$globalEnvironmentManipulator) {
return self::$globalEnvironmentManipulator->makeGlobalSettingsProvider();
return self::$globalEnvironmentManipulator->makeGlobalSettingsProvider($original);
} else {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/Application/EnvironmentManipulator.php
Expand Up @@ -23,7 +23,7 @@ interface EnvironmentManipulator
*
* @return GlobalSettingsProvider
*/
public function makeGlobalSettingsProvider();
public function makeGlobalSettingsProvider(GlobalSettingsProvider $original);

/**
* Create a custom PluginList kernel object, overriding the default behavior.@deprecated
Expand Down
2 changes: 2 additions & 0 deletions core/Tracker.php
Expand Up @@ -11,6 +11,8 @@
use Exception;
use Piwik\Plugins\BulkTracking\Tracker\Requests;
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig;
use Piwik\Config;
use Piwik\Tests\Framework\TestingEnvironmentVariables;
use Piwik\Tracker\Db as TrackerDb;
use Piwik\Tracker\Db\DbException;
use Piwik\Tracker\Handler;
Expand Down
26 changes: 14 additions & 12 deletions tests/PHPUnit/Framework/TestingEnvironmentManipulator.php
Expand Up @@ -55,9 +55,16 @@ public function __construct(TestingEnvironmentVariables $testingEnvironment, arr
$this->globalObservers = $globalObservers;
}

public function makeGlobalSettingsProvider()
public function makeGlobalSettingsProvider(GlobalSettingsProvider $original)
{
return new GlobalSettingsProvider($this->vars->configFileGlobal, $this->vars->configFileLocal, $this->vars->configFileCommon);
if ($this->vars->configFileGlobal
|| $this->vars->configFileLocal
|| $this->vars->configFileCommon
) {
return new GlobalSettingsProvider($this->vars->configFileGlobal, $this->vars->configFileLocal, $this->vars->configFileCommon);
} else {
return $original;
}
}

public function makePluginList(GlobalSettingsProvider $globalSettingsProvider)
Expand Down Expand Up @@ -128,22 +135,17 @@ public function getExtraDefinitions()
{
$testVarDefinitionSource = new TestingEnvironmentVariablesDefinitionSource($this->vars);

// Apply DI config from the fixture
$diConfig = array();
if ($this->vars->fixtureClass) {
$fixtureClass = $this->vars->fixtureClass;
if (class_exists($fixtureClass)) {
/** @var Fixture $fixture */
$fixture = new $fixtureClass;
$diConfig = $fixture->provideContainerConfig();
}
}

if ($this->vars->testCaseClass) {
$testCaseClass = $this->vars->testCaseClass;
if (class_exists($testCaseClass)) {
$testCase = new $testCaseClass();

// Apply DI config from the fixture
if (isset($testCaseClass::$fixture)) {
$diConfig = array_merge($diConfig, $testCaseClass::$fixture->provideContainerConfig());
}

if (method_exists($testCase, 'provideContainerConfigBeforeClass')) {
$diConfig = array_merge($diConfig, $testCaseClass::provideContainerConfigBeforeClass());
}
Expand Down

0 comments on commit 49311eb

Please sign in to comment.