Completed
Push — master ( 065cdd...96faaf )
by Alejandro
09:28
created

InstallCommandTest::testInputIsProperlyParsed()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 22
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 32
rs 8.8571
1
<?php
2
namespace ShlinkioTest\Shlink\CLI\Command\Install;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
use Prophecy\Argument;
6
use Prophecy\Prophecy\ObjectProphecy;
7
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
8
use Symfony\Component\Console\Application;
9
use Symfony\Component\Console\Helper\ProcessHelper;
10
use Symfony\Component\Console\Tester\CommandTester;
11
use Symfony\Component\Process\Process;
12
use Zend\Config\Writer\WriterInterface;
13
14
class InstallCommandTest extends TestCase
15
{
16
    /**
17
     * @var CommandTester
18
     */
19
    protected $commandTester;
20
    /**
21
     * @var ObjectProphecy
22
     */
23
    protected $configWriter;
24
25
    public function setUp()
26
    {
27
        $processMock = $this->prophesize(Process::class);
28
        $processMock->isSuccessful()->willReturn(true);
29
        $processHelper = $this->prophesize(ProcessHelper::class);
30
        $processHelper->getName()->willReturn('process');
31
        $processHelper->setHelperSet(Argument::any())->willReturn(null);
32
        $processHelper->run(Argument::cetera())->willReturn($processMock->reveal());
33
34
        $app = new Application();
35
        $helperSet = $app->getHelperSet();
36
        $helperSet->set($processHelper->reveal());
37
        $app->setHelperSet($helperSet);
38
39
        $this->configWriter = $this->prophesize(WriterInterface::class);
40
        $command = new InstallCommand($this->configWriter->reveal());
41
        $app->add($command);
42
43
        $questionHelper = $command->getHelper('question');
44
        $questionHelper->setInputStream($this->createInputStream());
45
        $this->commandTester = new CommandTester($command);
46
    }
47
48 View Code Duplication
    protected function createInputStream()
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...
49
    {
50
        $stream = fopen('php://memory', 'r+', false);
51
        fputs($stream, <<<CLI_INPUT
52
53
shlink_db
54
alejandro
55
1234
56
0
57
doma.in
58
abc123BCA
59
60
1
61
my_secret
62
CLI_INPUT
63
        );
64
        rewind($stream);
65
66
        return $stream;
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function testInputIsProperlyParsed()
73
    {
74
        $this->configWriter->toFile(Argument::any(), [
75
            'app_options' => [
76
                'secret_key' => 'my_secret',
77
            ],
78
            'entity_manager' => [
79
                'connection' => [
80
                    'driver' => 'pdo_mysql',
81
                    'dbname' => 'shlink_db',
82
                    'user' => 'alejandro',
83
                    'password' => '1234',
84
                ],
85
            ],
86
            'translator' => [
87
                'locale' => 'en',
88
            ],
89
            'cli' => [
90
                'locale' => 'es',
91
            ],
92
            'url_shortener' => [
93
                'domain' => [
94
                    'schema' => 'http',
95
                    'hostname' => 'doma.in',
96
                ],
97
                'shortcode_chars' => 'abc123BCA',
98
            ],
99
        ], false)->shouldBeCalledTimes(1);
100
        $this->commandTester->execute([
101
            'command' => 'shlink:install',
102
        ]);
103
    }
104
}
105