/
EnvironmentTest.php
86 lines (68 loc) · 2.55 KB
/
EnvironmentTest.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
<?php
class TestEnvironment extends PHPUnit_Framework_TestCase
{
/**
* Test in which environment the application will run.
*/
public function testWhichEnvironmentDefault()
{
$locations = [
'local' => ['local-hostname', 'another-host', 'team-localhost'],
'production' => 'prod-hostname',
];
// If nothing is found - Should return empty string.
$env = new Thms\Config\Environment($locations);
$this->assertEquals('', $env->which());
// Simulate local hostname.
$this->assertEquals('local', $env->which('team-localhost'));
$this->assertEquals('production', $env->which('prod-hostname'));
}
/**
* Test in which environment the application will run by using a Closure.
*/
public function testWhichEnvironmentWithClosure()
{
$locations = function () {
return 'local';
};
$env = new Thms\Config\Environment($locations);
$this->assertEquals('local', $env->which('some-host'));
$locations = function () {
$host = null;
if (true) {
$host = 'local';
}
};
$env = new Thms\Config\Environment($locations);
$this->assertNotEquals('local', $env->which());
$this->assertEquals('', $env->which());
}
/**
* Test in which environment the application will run by using string.
*/
public function testWhichEnvironmentWithString()
{
$locations = '';
$env = new Thms\Config\Environment($locations);
$this->assertEquals('', $env->which());
$locations = 'local';
$env = new \Thms\Config\Environment($locations);
$this->assertEquals('local', $env->which());
}
public function testWhichEnvironmentWithRegEx()
{
$locations = [
'local' => '*.themosis.dev',
'production' => '*.aws.elastic456278s9d.com',
'staging' => 'xyz\..+\.net',
'custom' => 'my-hostname',
];
$env = new Thms\Config\Environment($locations);
$this->assertEquals('local', $env->which('server001.themosis.dev'));
$this->assertEquals('local', $env->which('abcserver3578sdd67.themosis.dev'));
$this->assertEquals('production', $env->which('us2-467.aws.elastic456278s9d.com'));
$this->assertEquals('staging', $env->which('xyz.some-name.net'));
$this->assertEquals('staging', $env->which('xyz.another_name215658.net'));
$this->assertEquals('custom', $env->which('my-hostname'));
}
}