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

DecryptTest::testDecryptMissingFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 10
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 DecryptTest extends TestCase
10
{
11
    use HandlesEnvFiles;
12
13
    public function testDecrypt()
14
    {
15
        $this->saveEncrypted(EnvSecurity::encrypt('hello world'), 'testing');
16
17
        $this->artisan('env:decrypt testing')
18
            ->expectsOutput('Successfully decrypted .env for environment [testing]');
19
20
        $this->assertTrue(file_exists(__DIR__ . "/.env-saved"));
21
        $this->assertEquals('hello world', file_get_contents(__DIR__ . "/.env-saved"));
22
    }
23
24
    public function testDecryptMissingFile()
25
    {
26
        // Make sure no file is present
27
        if(file_exists($this->getFilePathForEnvironment('testing'))) {
28
            unlink($this->getFilePathForEnvironment('testing'));
29
        }
30
31
        // Our test double will output the plaintext
32
        $this->artisan('env:decrypt testing')
33
            ->expectsOutput('Unable to load encrypted .env file for environment [testing]');
34
    }
35
36
    public function testDecryptResolveEnvironment()
37
    {
38
        EnvSecurity::resolveEnvironmentUsing(function() {
39
            return 'foobar';
40
        });
41
42
        $this->saveEncrypted(EnvSecurity::encrypt('heya'), 'foobar');
43
44
        $this->artisan('env:decrypt')
45
            ->expectsOutput('Successfully decrypted .env for environment [foobar]');
46
47
        $this->assertTrue(file_exists(__DIR__ . "/.env-saved"));
48
        $this->assertEquals('heya', file_get_contents(__DIR__ . "/.env-saved"));
49
    }
50
}