ConfigYamlTest.php
2.07 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
<?php
namespace Test\Phinx\Config;
use \Phinx\Config\Config;
/**
* Class ConfigYamlTest
* @package Test\Phinx\Config
* @group config
*/
class ConfigYamlTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers \Phinx\Config\Config::fromYaml
* @covers \Phinx\Config\Config::getDefaultEnvironment
* @expectedException \RuntimeException
*/
public function testGetDefaultEnvironmentWithAnEmptyYamlFile()
{
// test using a Yaml file with no key or entries
$path = __DIR__ . '/_files';
$config = Config::fromYaml($path . '/empty.yml');
$config->getDefaultEnvironment();
}
/**
* @covers \Phinx\Config\Config::fromYaml
* @covers \Phinx\Config\Config::getDefaultEnvironment
* @expectedException \RuntimeException
* @expectedExceptionMessage The environment configuration for 'staging' is missing
*/
public function testGetDefaultEnvironmentWithAMissingEnvironmentEntry()
{
// test using a Yaml file with a 'default_database' key, but without a
// corresponding entry
$path = __DIR__ . '/_files';
$config = Config::fromYaml($path . '/missing_environment_entry.yml');
$config->getDefaultEnvironment();
}
/**
* @covers \Phinx\Config\Config::getDefaultEnvironment
*/
public function testGetDefaultEnvironmentMethod()
{
$path = __DIR__ . '/_files';
// test using a Yaml file without the 'default_database' key.
// (it should default to the first one).
$config = Config::fromYaml($path . '/no_default_database_key.yml');
$this->assertEquals('production', $config->getDefaultEnvironment());
// test using environment variable PHINX_ENVIRONMENT
// (it should return the configuration specified in the environment)
putenv('PHINX_ENVIRONMENT=externally-specified-environment');
$config = Config::fromYaml($path . '/no_default_database_key.yml');
$this->assertEquals('externally-specified-environment', $config->getDefaultEnvironment());
putenv('PHINX_ENVIRONMENT=');
}
}