Test Setup Failed
Push — develop ( fb72f9...afdb67 )
by Joseph
03:04
created

anonymous//tests/EditTest.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
wmc 1
1
<?php
2
3
namespace Tests;
4
5
use Config;
6
use EnvSecurity;
0 ignored issues
show
Bug introduced by
The type EnvSecurity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use STS\EnvSecurity\Console\Concerns\HandlesEnvFiles;
8
9
class EditTest extends TestCase
10
{
11
    use HandlesEnvFiles;
12
13
    public function testEditEmptyFile()
14
    {
15
        // Make sure no file is present
16
        if(file_exists($this->getFilePathForEnvironment('testing'))) {
17
            unlink($this->getFilePathForEnvironment('testing'));
18
        }
19
20
        // Setup a driver that fails if we call the encrypt method.
21
        EnvSecurity::extend('failonencrypt', function() {
22
            return new class {
23
                public function encrypt($plaintext) {
24
                    throw new \Exception('Should not be here. I received: ' . $plaintext);
25
                }
26
            };
27
        });
28
        Config::set('env-security.default', 'failonencrypt');
29
30
        // Our test double will output the plaintext
31
        $this->artisan('env:edit testing')
32
            ->expectsOutput('Plaintext contents: ');
33
34
        // File should be empty
35
        $this->assertEquals('', $this->loadEncrypted('testing'));
36
    }
37
38
    public function testEditEncryptedFile()
39
    {
40
        // Setup a testing.env.enc file
41
        $this->saveEncrypted(EnvSecurity::encrypt('hello world'), "testing");
42
43
        // Our test double will output the plaintext
44
        $this->artisan('env:edit testing --append modified')
45
            ->expectsOutput('Plaintext contents: hello world');
46
47
        // File will have "modified" appended and be re-encrypted
48
        $this->assertEquals(EnvSecurity::encrypt('hello world modified'), $this->loadEncrypted('testing'));
49
    }
50
}