|
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
|
|
|
protected function createInputStream() |
|
49
|
|
|
{ |
|
50
|
|
|
$stream = fopen('php://memory', 'rb+', false); |
|
51
|
|
|
fwrite($stream, <<<CLI_INPUT |
|
52
|
|
|
|
|
53
|
|
|
shlink_db |
|
54
|
|
|
alejandro |
|
55
|
|
|
1234 |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
0 |
|
59
|
|
|
doma.in |
|
60
|
|
|
abc123BCA |
|
61
|
|
|
|
|
62
|
|
|
1 |
|
63
|
|
|
my_secret |
|
64
|
|
|
CLI_INPUT |
|
65
|
|
|
); |
|
66
|
|
|
rewind($stream); |
|
67
|
|
|
|
|
68
|
|
|
return $stream; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @test |
|
73
|
|
|
*/ |
|
74
|
|
|
public function inputIsProperlyParsed() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->configWriter->toFile(Argument::any(), [ |
|
77
|
|
|
'app_options' => [ |
|
78
|
|
|
'secret_key' => 'my_secret', |
|
79
|
|
|
], |
|
80
|
|
|
'entity_manager' => [ |
|
81
|
|
|
'connection' => [ |
|
82
|
|
|
'driver' => 'pdo_mysql', |
|
83
|
|
|
'dbname' => 'shlink_db', |
|
84
|
|
|
'user' => 'alejandro', |
|
85
|
|
|
'password' => '1234', |
|
86
|
|
|
'host' => 'localhost', |
|
87
|
|
|
'port' => '3306', |
|
88
|
|
|
'driverOptions' => [ |
|
89
|
|
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', |
|
90
|
|
|
] |
|
91
|
|
|
], |
|
92
|
|
|
], |
|
93
|
|
|
'translator' => [ |
|
94
|
|
|
'locale' => 'en', |
|
95
|
|
|
], |
|
96
|
|
|
'cli' => [ |
|
97
|
|
|
'locale' => 'es', |
|
98
|
|
|
], |
|
99
|
|
|
'url_shortener' => [ |
|
100
|
|
|
'domain' => [ |
|
101
|
|
|
'schema' => 'http', |
|
102
|
|
|
'hostname' => 'doma.in', |
|
103
|
|
|
], |
|
104
|
|
|
'shortcode_chars' => 'abc123BCA', |
|
105
|
|
|
], |
|
106
|
|
|
], false)->shouldBeCalledTimes(1); |
|
107
|
|
|
$this->commandTester->execute([ |
|
108
|
|
|
'command' => 'shlink:install', |
|
109
|
|
|
]); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|