2 namespace Drush\Config;
4 use PHPUnit\Framework\TestCase;
7 * Test the config loader. Also exercises the EnvironmentConfigLoader.
9 class ConfigLocatorTest extends TestCase
11 use \Drush\FixtureFactory;
14 * Test a config locator initialized only with data from the fixture's environment
16 function testOnlyEnvironmentData()
18 $configLocator = new ConfigLocator('TEST_');
19 $configLocator->addEnvironment($this->environment());
20 $config = $configLocator->config();
21 $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
25 * Test a comprehensive load of all default fixture data.
27 function testLoadAll()
29 $configLocator = $this->createConfigLocator();
31 $sources = $configLocator->sources();
32 //$this->assertEquals('environment', $sources['env']['cwd']);
33 $this->assertEquals($this->fixturesDir() . '/etc/drush/drush.yml', $sources['test']['system']);
34 $this->assertEquals($this->fixturesDir() . '/etc/drush/drushVARIANT.yml', $sources['test']['variant']);
35 $this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', $sources['test']['home']);
36 $this->assertEquals($this->fixturesDir() . '/sites/d8/drush/drush.yml', $sources['test']['site']);
37 $this->assertEquals($this->environment()->drushBasePath() . '/drush.yml', $sources['drush']['php']['minimum-version']);
39 $config = $configLocator->config();
41 $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
42 $this->assertEquals('A system-wide setting', $config->get('test.system'));
43 $this->assertEquals('A user-specific setting', $config->get('test.home'));
44 $this->assertEquals('A site-specific setting', $config->get('test.site'));
45 $this->assertTrue($config->has('drush.php.minimum-version'));
49 * Test loading default fixture data in 'local' mode. This prevents Drush
50 * from loading any configuration file in any "global" location. In this
51 * context, "global" means anything that is not site-local, including the
52 * configuration file in the user's home directory, etc.
54 function testLocalMode()
56 $configLocator = $this->createConfigLocator(true);
59 $sources = $configLocator->sources();
60 //$this->assertEquals('environment', $sources['env']['cwd']);
61 $this->assertArrayNotHasKey('system', $sources['test']);
62 $this->assertArrayNotHasKey('home', $sources['test']);
63 $this->assertEquals($this->siteDir() . '/drush/drush.yml', $sources['test']['site']);
66 $config = $configLocator->config();
67 $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
68 $this->assertFalse($config->has('test.system'));
69 $this->assertFalse($config->has('test.home'));
70 $this->assertEquals('A site-specific setting', $config->get('test.site'));
73 function testAliasPaths()
75 $configLocator = $this->createConfigLocator();
76 $aliasPaths = $configLocator->getSiteAliasPaths(['/home/user/aliases'], $this->environment());
77 $aliasPaths = array_map(
79 return str_replace(dirname(__DIR__) . '/', '', $item);
85 $expected = '/home/user/aliases,fixtures/sites/d8/drush/sites';
86 $this->assertEquals($expected, implode(',', $aliasPaths));
90 * Create a config locator from All The Sources, for use in multiple tests.
92 protected function createConfigLocator($isLocal = false, $configPath = '')
94 $configLocator = new ConfigLocator('TEST_', 'VARIANT');
95 $configLocator->collectSources();
96 $configLocator->setLocal($isLocal);
97 $configLocator->addUserConfig([$configPath], $this->environment()->systemConfigPath(), $this->environment()->userConfigPath());
98 $configLocator->addDrushConfig($this->environment()->drushBasePath());
100 // Make our environment settings available as configuration items
101 $configLocator->addEnvironment($this->environment());
103 $configLocator->addSitewideConfig($this->siteDir());
105 return $configLocator;