ConfigDefaultEnvironmentTest.php
2.29 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
72
73
74
75
<?php
namespace Test\Phinx\Config;
use \Phinx\Config\Config;
/**
* Class ConfigDefaultEnvironmentTest
* @package Test\Phinx\Config
* @group config
* @covers \Phinx\Config\Config::getDefaultEnvironment
*/
class ConfigDefaultEnvironmentTest extends AbstractConfigTest
{
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']);
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The environment configuration (read from $PHINX_ENVIRONMENT) for 'conf-test' is missing
*/
public function testGetDefaultEnvironmentOverridenByEnvButNotSet()
{
// set dummy
$dummyEnv = 'conf-test';
putenv('PHINX_ENVIRONMENT=' . $dummyEnv);
try {
$config = new Config(array());
$config->getDefaultEnvironment();
}
catch (\Exception $e) {
// reset back to normal
putenv('PHINX_ENVIRONMENT=');
// throw again in order to finish test
throw $e;
}
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Could not find a default environment
*/
public function testGetDefaultEnvironmentOverridenFailedToFind()
{
// set empty env var
putenv('PHINX_ENVIRONMENT=');
$config = new Config(array());
$config->getDefaultEnvironment();
}
}