Newer
Older
diosmosis
a validé
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Framework;
use Piwik\Application\EnvironmentManipulator;
use Piwik\Application\Kernel\GlobalSettingsProvider;
/**
* Manipulates an environment for tests.
*/
class TestingEnvironmentManipulator implements EnvironmentManipulator
{
/**
* @var TestingEnvironmentVariables
*/
private $vars;
private $globalObservers;
public function __construct(TestingEnvironmentVariables $testingEnvironment, array $globalObservers = array())
{
$this->vars = $testingEnvironment;
$this->globalObservers = $globalObservers;
}
public function makeGlobalSettingsProvider()
{
return new GlobalSettingsProvider($this->vars->configFileGlobal, $this->vars->configFileLocal, $this->vars->configFileCommon);
}
public function beforeContainerCreated()
{
if ($this->vars->queryParamOverride) {
foreach ($this->vars->queryParamOverride as $key => $value) {
$_GET[$key] = $value;
}
}
if ($this->vars->globalsOverride) {
foreach ($this->vars->globalsOverride as $key => $value) {
$GLOBALS[$key] = $value;
}
}
if ($this->vars->hostOverride) {
\Piwik\Url::setHost($this->vars->hostOverride);
}
if ($this->vars->useXhprof) {
\Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
}
\Piwik\Cache\Backend\File::$invalidateOpCacheBeforeRead = true;
}
public function getExtraDefinitions()
{
// 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();
if (method_exists($testCase, 'provideContainerConfigBeforeClass')) {
$diConfig = array_merge($diConfig, $testCaseClass::provideContainerConfigBeforeClass());
}
if (method_exists($testCase, 'provideContainerConfig')) {
$diConfig = array_merge($diConfig, $testCase->provideContainerConfig());
}
}
}
return array(
$diConfig,
array('observers.global' => \DI\add($this->globalObservers))
);
}
}