-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ConfigLocatorTest.php
131 lines (109 loc) · 5.16 KB
/
ConfigLocatorTest.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
namespace Drush\Config;
use Unish\Utils\Fixtures;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Path;
/**
* Test the config loader. Also exercises the EnvironmentConfigLoader.
*/
class ConfigLocatorTest extends TestCase
{
use Fixtures;
/**
* Test a config locator initialized only with data from the fixture's environment
*/
public function testOnlyEnvironmentData()
{
$configLocator = new ConfigLocator('TEST_');
$configLocator->addEnvironment($this->environment());
$config = $configLocator->config();
$this->assertEquals($this->homeDir(), $config->get('env.cwd'));
}
/**
* Test a comprehensive load of all default fixture data.
*/
public function testLoadAll()
{
$configLocator = $this->createConfigLocator();
$sources = $configLocator->sources();
//$this->assertEquals('environment', $sources['env']['cwd']);
$this->assertEquals($this->fixturesDir() . '/etc/drush/drush.yml', Path::canonicalize($sources['test']['system']));
$this->assertEquals($this->fixturesDir() . '/etc/drush/drushVARIANT.yml', Path::canonicalize($sources['test']['variant']));
$this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', Path::canonicalize($sources['test']['home']));
$this->assertEquals($this->fixturesDir() . '/sites/d8/drush/drush.yml', Path::canonicalize($sources['test']['site']));
$this->assertEquals($this->environment()->drushBasePath() . '/drush.yml', Path::canonicalize($sources['drush']['php']['minimum-version']));
$config = $configLocator->config();
$this->assertEquals($this->homeDir(), $config->get('env.cwd'));
$this->assertEquals('A system-wide setting', $config->get('test.system'));
$this->assertEquals('A user-specific setting', $config->get('test.home'));
$this->assertEquals('A site-specific setting', $config->get('test.site'));
$this->assertTrue($config->has('drush.php.minimum-version'));
}
/**
* Test loading default fixture data in 'local' mode. This prevents Drush
* from loading any configuration file in any "global" location. In this
* context, "global" means anything that is not site-local, including the
* configuration file in the user's home directory, etc.
*/
public function testLocalMode()
{
$configLocator = $this->createConfigLocator(true);
/*
$sources = $configLocator->sources();
//$this->assertEquals('environment', $sources['env']['cwd']);
$this->assertArrayNotHasKey('system', $sources['test']);
$this->assertArrayNotHasKey('home', $sources['test']);
$this->assertEquals($this->siteDir() . '/drush/drush.yml', $sources['test']['site']);
*/
$config = $configLocator->config();
$this->assertEquals($this->homeDir(), $config->get('env.cwd'));
$this->assertFalse($config->has('test.system'));
$this->assertFalse($config->has('test.home'));
$this->assertEquals('A site-specific setting', $config->get('test.site'));
}
public function testAliasPaths()
{
$configLocator = $this->createConfigLocator();
$aliasPaths = $configLocator->getSiteAliasPaths(['/home/user/aliases'], $this->environment());
$aliasPaths = array_map(
function ($item) {
return str_replace(Path::canonicalize(dirname(__DIR__)), '', $item);
},
$aliasPaths
);
sort($aliasPaths);
$expected = ['/fixtures/sites/d8/drush/sites', '/fixtures/sites/drush/sites', '/home/user/aliases'];
$this->assertEquals($expected, $aliasPaths);
}
/**
* Test an env var supersedes user's configuration file.
*/
public function testEnvVar()
{
$configLocator = $this->createConfigLocator();
$sources = $configLocator->sources();
$this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', Path::canonicalize($sources['test']['home']));
$config = $configLocator->config();
$this->assertEquals('A user-specific setting', $config->get('test.home'));
putenv('TEST_HOME=An env overridden setting');
$this->assertNotEquals('A user-specific setting', $config->get('test.home'));
$this->assertEquals('An env overridden setting', $config->get('test.home'));
putenv('TEST_HOME');
}
/**
* Create a config locator from All The Sources, for use in multiple tests.
*/
protected function createConfigLocator($isLocal = false, $configPath = '')
{
$configLocator = new ConfigLocator('TEST_', 'VARIANT');
$configLocator->collectSources();
$configLocator->setLocal($isLocal);
$configLocator->addUserConfig([$configPath], $this->environment()->systemConfigPath(), $this->environment()->userConfigPath());
$configLocator->addDrushConfig($this->environment()->drushBasePath());
// Make our environment settings available as configuration items
$configLocator->addEnvironment($this->environment());
$configLocator->addSitewideConfig($this->siteDir());
return $configLocator;
}
}