Completed
Push — master ( 7bd887...148650 )
by Bill
11s
created

EnvironmentFinderTest::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
use Bmitch\Envsync\Finders\EnvironmentFinder;
4
5
class EnvironmentFinderTest extends FileSystemTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * @test
9
     */
10 View Code Duplication
    public function it_can_find_an_environment_varaible_in_a_dot_env_file()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
		file_put_contents("{$this->path}/.env", 'FOOBAR=BAZ');
13
    	$result = $this->envFinder->getFromFile("{$this->path}/.env");
0 ignored issues
show
Bug introduced by
The property envFinder does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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