Passed
Branch master (b47b37)
by Anton
01:59
created

KeyCommandTest::testMountFileNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
9
10
namespace Spiral\Framework\Encrypter;
11
12
use Spiral\Encrypter\EncrypterFactory;
13
use Spiral\Framework\ConsoleTest;
14
15
class KeyCommandTest extends ConsoleTest
16
{
17
    public function testKey()
18
    {
19
        $key = $this->runCommand('encrypt:key');
20
        $this->assertNotEmpty($key);
21
    }
22
23
    public function testMountFileNotFound()
24
    {
25
        $out = $this->runCommand('encrypt:key', [
26
            '-m' => __DIR__ . '/.env'
27
        ]);
28
29
        $this->assertContains('Unable to find', $out);
30
    }
31
32
    public function testReplace()
33
    {
34
        file_put_contents(__DIR__ . '/.env', '{encrypt-key}');
35
36
        $out = $this->runCommand('encrypt:key', [
37
            '-m' => __DIR__ . '/.env'
38
        ]);
39
40
        $this->assertContains('key has been updated', $out);
41
42
        $body = file_get_contents(__DIR__ . '/.env');
43
        $this->assertContains($body, $out);
44
45
        unlink(__DIR__ . '/.env');
46
    }
47
48
    public function testReplaceCurrent()
49
    {
50
        $key = $this->app->get(EncrypterFactory::class)->generateKey();
51
52
        $app = $this->makeApp([
53
            'ENCRYPTER_KEY' => $key
54
        ]);
55
56
        file_put_contents(__DIR__ . '/.env', $key);
57
58
        $out = $app->console()->run('encrypt:key', [
59
            '-m' => __DIR__ . '/.env'
60
        ]);
61
        $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

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