Passed
Pull Request — master (#277)
by Kirill
03:11
created

KeyCommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testKey() 0 4 1
A testReplaceCurrent() 0 21 1
A testMountFileNotFound() 0 7 1
A testReplace() 0 14 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Framework\Encrypter;
13
14
use Spiral\Encrypter\EncrypterFactory;
15
use Spiral\Tests\Framework\ConsoleTest;
16
17
class KeyCommandTest extends ConsoleTest
18
{
19
    public function testKey(): void
20
    {
21
        $key = $this->runCommand('encrypt:key');
22
        $this->assertNotEmpty($key);
23
    }
24
25
    public function testMountFileNotFound(): void
26
    {
27
        $out = $this->runCommand('encrypt:key', [
28
            '-m' => __DIR__ . '/.env'
29
        ]);
30
31
        $this->assertStringContainsString('Unable to find', $out);
32
    }
33
34
    public function testReplace(): void
35
    {
36
        file_put_contents(__DIR__ . '/.env', '{encrypt-key}');
37
38
        $out = $this->runCommand('encrypt:key', [
39
            '-m' => __DIR__ . '/.env'
40
        ]);
41
42
        $this->assertStringContainsString('key has been updated', $out);
43
44
        $body = file_get_contents(__DIR__ . '/.env');
45
        $this->assertStringContainsString($body, $out);
46
47
        unlink(__DIR__ . '/.env');
48
    }
49
50
    public function testReplaceCurrent(): void
51
    {
52
        $key = $this->app->get(EncrypterFactory::class)->generateKey();
53
54
        $app = $this->makeApp([
55
            'ENCRYPTER_KEY' => $key
56
        ]);
57
58
        file_put_contents(__DIR__ . '/.env', $key);
59
60
        $out = $app->console()->run('encrypt:key', [
61
            '-m' => __DIR__ . '/.env'
62
        ]);
63
        $out = $out->getOutput()->fetch();
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Symfony\Component\Console\Output\OutputInterface. It seems like you code against a sub-type of Symfony\Component\Console\Output\OutputInterface such as Symfony\Component\Console\Output\BufferedOutput. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $out = $out->getOutput()->/** @scrutinizer ignore-call */ fetch();
Loading history...
64
65
        $this->assertStringContainsString('key has been updated', $out);
66
67
        $body = file_get_contents(__DIR__ . '/.env');
68
        $this->assertStringContainsString($body, $out);
69
70
        unlink(__DIR__ . '/.env');
71
    }
72
}
73