1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Bmitch\Envsync\Finders\EnvironmentFinder; |
4
|
|
|
|
5
|
|
|
class EnvironmentFinderTest extends FileSystemTest |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @test |
9
|
|
|
*/ |
10
|
|
View Code Duplication |
public function it_can_find_an_environment_varaible_in_a_dot_env_file() |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
file_put_contents("{$this->path}/.env", 'FOOBAR=BAZ'); |
13
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env"); |
|
|
|
|
14
|
|
|
$this->assertCount(1, $result); |
15
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function it_can_find_multiple_environment_varaibles_in_a_dot_env_file() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
file_put_contents("{$this->path}/.env", "FOOBAR=BAZ\nBAZBAR=FOO"); |
24
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env"); |
25
|
|
|
$this->assertCount(2, $result); |
26
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
27
|
|
|
$this->assertEquals('BAZBAR', $result[1]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function it_can_find_zero_environment_varaibles_in_a_dot_env_file() |
34
|
|
|
{ |
35
|
|
|
file_put_contents("{$this->path}/.env", ""); |
36
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env"); |
37
|
|
|
$this->assertCount(0, $result); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function it_can_find_an_environment_varaible_in_a_dot_env_example_file() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
file_put_contents("{$this->path}/.env.example", 'FOOBAR=BAZ'); |
46
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env.example"); |
47
|
|
|
$this->assertCount(1, $result); |
48
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function it_can_find_multiple_environment_varaibles_in_a_dot_env_example_file() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
file_put_contents("{$this->path}/.env.example", "FOOBAR=BAZ\nBAZBAR=FOO"); |
57
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env.example"); |
58
|
|
|
$this->assertCount(2, $result); |
59
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
60
|
|
|
$this->assertEquals('BAZBAR', $result[1]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function it_can_find_zero_environment_varaibles_in_a_dot_env_example_file() |
67
|
|
|
{ |
68
|
|
|
file_put_contents("{$this->path}/.env.example", ""); |
69
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env.example"); |
70
|
|
|
$this->assertCount(0, $result); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function it_can_find_an_environment_varaible_in_a_php_file() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
file_put_contents("{$this->path}/foobar.php", "env('FOOBAR');"); |
79
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/foobar.php"); |
80
|
|
|
$this->assertCount(1, $result); |
81
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function it_can_find_multiple_environment_varaibles_in_a_php_file() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
file_put_contents("{$this->path}/foobar.php", "env('FOOBAR'); env('BARBAZ');"); |
90
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/foobar.php"); |
91
|
|
|
$this->assertCount(2, $result); |
92
|
|
|
$this->assertEquals('FOOBAR', $result[0]); |
93
|
|
|
$this->assertEquals('BARBAZ', $result[1]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @test |
98
|
|
|
*/ |
99
|
|
|
public function it_can_find_zero_environment_varaibles_in_a_php_file() |
100
|
|
|
{ |
101
|
|
|
file_put_contents("{$this->path}/foobar.php", ""); |
102
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/foobar.php"); |
103
|
|
|
$this->assertCount(0, $result); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
*/ |
109
|
|
|
public function if_the_php_file_doesnt_exist_then_no_results_are_found() |
110
|
|
|
{ |
111
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/foobar.php"); |
112
|
|
|
$this->assertCount(0, $result); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @test |
117
|
|
|
*/ |
118
|
|
|
public function if_the_dot_env_file_doesnt_exist_then_no_results_are_found() |
119
|
|
|
{ |
120
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env"); |
121
|
|
|
$this->assertCount(0, $result); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @test |
126
|
|
|
*/ |
127
|
|
|
public function if_the_dont_env_example_file_doesnt_exist_then_no_results_are_found() |
128
|
|
|
{ |
129
|
|
|
$result = $this->envFinder->getFromFile("{$this->path}/.env.example"); |
130
|
|
|
$this->assertCount(0, $result); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setup() |
134
|
|
|
{ |
135
|
|
|
parent::setup(); |
136
|
|
|
$this->envFinder = new EnvironmentFinder; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.