-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDotenvTest.php
93 lines (78 loc) · 3.19 KB
/
DotenvTest.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
87
88
89
90
91
92
93
<?php
namespace Test\DevCoder;
use DevCoder\DotEnv;
use PHPUnit\Framework\TestCase;
class DotenvTest extends TestCase
{
private function env(string $file)
{
return __DIR__ . DIRECTORY_SEPARATOR . 'env' . DIRECTORY_SEPARATOR . $file;
}
/**
* @runInSeparateProcess
*/
public function testLoad() {
(new DotEnv($this->env('.env.default')))->load();
$this->assertEquals('dev', getenv('APP_ENV'));
$this->assertEquals('mysql:host=localhost;dbname=test;', getenv('DATABASE_DNS'));
$this->assertEquals('root', getenv('DATABASE_USER'));
$this->assertEquals('password', getenv('DATABASE_PASSWORD'));
$this->assertFalse(getenv('GOOGLE_API'));
$this->assertFalse(getenv('GOOGLE_MANAGER_KEY'));
$this->assertEquals('dev', $_ENV['APP_ENV']);
$this->assertEquals('mysql:host=localhost;dbname=test;', $_ENV['DATABASE_DNS']);
$this->assertEquals('root', $_ENV['DATABASE_USER']);
$this->assertEquals('password', $_ENV['DATABASE_PASSWORD']);
$this->assertFalse(array_key_exists('GOOGLE_API', $_ENV));
$this->assertFalse(array_key_exists('GOOGLE_MANAGER_KEY', $_ENV));
$this->assertEquals('dev', $_SERVER['APP_ENV']);
$this->assertEquals('mysql:host=localhost;dbname=test;', $_SERVER['DATABASE_DNS']);
$this->assertEquals('root', $_SERVER['DATABASE_USER']);
$this->assertEquals('password', $_SERVER['DATABASE_PASSWORD']);
$this->assertFalse(array_key_exists('GOOGLE_API', $_SERVER));
$this->assertFalse(array_key_exists('GOOGLE_MANAGER_KEY', $_SERVER));
}
public function testFileNotExist() {
$this->expectException(\InvalidArgumentException::class);
(new DotEnv($this->env('.env.not-exists')))->load();
}
/**
* @runInSeparateProcess
*/
public function testLoadReturnsValues()
{
$loaded = (new DotEnv($this->env('.env.return')))->load();
$this->assertEquals('returned', $loaded['VALUE']);
$this->assertEquals('returned', $_ENV['VALUE']);
}
/**
* @runInSeparateProcess
*/
public function testProcessBoolean()
{
(new DotEnv($this->env('.env.boolean'), [
DotEnv::PROCESS_BOOLEANS => true
]))->load();
$this->assertEquals(false, $_ENV['FALSE1']);
$this->assertEquals(false, $_ENV['FALSE2']);
$this->assertEquals(false, $_ENV['FALSE3']);
$this->assertEquals("'false'", $_ENV['FALSE4']);
$this->assertEquals('0', $_ENV['FALSE5']);
$this->assertEquals(true, $_ENV['TRUE1']);
$this->assertEquals(true, $_ENV['TRUE2']);
$this->assertEquals(true, $_ENV['TRUE3']);
$this->assertEquals("'true'", $_ENV['TRUE4']);
$this->assertEquals('1', $_ENV['TRUE5']);
}
/**
* @runInSeparateProcess
*/
public function testDontProcessBoolean()
{
(new DotEnv($this->env('.env.boolean'), [
DotEnv::PROCESS_BOOLEANS => false
]))->load();
$this->assertEquals('false', $_ENV['FALSE1']);
$this->assertEquals('true', $_ENV['TRUE1']);
}
}