-
Notifications
You must be signed in to change notification settings - Fork 887
Expand file tree
/
Copy pathConfigDefaultEnvironmentTest.php
More file actions
71 lines (60 loc) · 2.19 KB
/
Copy pathConfigDefaultEnvironmentTest.php
File metadata and controls
71 lines (60 loc) · 2.19 KB
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
<?php
namespace Test\Phinx\Config;
use Phinx\Config\Config;
use RuntimeException;
/**
* Class ConfigDefaultEnvironmentTest
*
* @package Test\Phinx\Config
* @group config
* @covers \Phinx\Config\Config::getDefaultEnvironment
*/
class ConfigDefaultEnvironmentTest extends AbstractConfigTestCase
{
public function testGetDefaultEnvironment()
{
// test with the config array
$configArray = $this->getConfigArray();
$config = new Config($configArray);
$this->assertEquals('testing', $config->getDefaultEnvironment());
}
public function testConfigReplacesTokensWithEnvVariables()
{
$_SERVER['PHINX_DBHOST'] = 'localhost';
$_SERVER['PHINX_DBNAME'] = 'productionapp';
$_SERVER['PHINX_DBUSER'] = 'root';
$_SERVER['PHINX_DBPASS'] = 'ds6xhj1';
$_SERVER['PHINX_DBPORT'] = '1234';
$path = __DIR__ . '/_files';
$config = Config::fromYaml($path . '/external_variables.yml');
$env = $config->getEnvironment($config->getDefaultEnvironment());
$this->assertEquals('localhost', $env['host']);
$this->assertEquals('productionapp', $env['name']);
$this->assertEquals('root', $env['user']);
$this->assertEquals('ds6xhj1', $env['pass']);
$this->assertEquals('1234', $env['port']);
}
public function testGetDefaultEnvironmentOverridenByEnvButNotSet()
{
// set dummy
$dummyEnv = 'conf-test';
putenv('PHINX_ENVIRONMENT=' . $dummyEnv);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The environment configuration (read from $PHINX_ENVIRONMENT) for \'conf-test\' is missing');
try {
$config = new Config([]);
$config->getDefaultEnvironment();
} finally {
putenv('PHINX_ENVIRONMENT=');
}
}
public function testGetDefaultEnvironmentOverridenFailedToFind()
{
// set empty env var
putenv('PHINX_ENVIRONMENT=');
$config = new Config([]);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Could not find a default environment');
$config->getDefaultEnvironment();
}
}