]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php
manage assets through npm
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Command / InstallCommandTest.php
CommitLineData
0bf99bb1
J
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Command;
4
619cc453
JB
5use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
6use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
0bf99bb1 7use Symfony\Bundle\FrameworkBundle\Console\Application;
0bf99bb1
J
8use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Output\NullOutput;
619cc453
JB
10use Symfony\Component\Console\Tester\CommandTester;
11use Wallabag\CoreBundle\Command\InstallCommand;
12use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock;
13use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
0bf99bb1 14
769e19dc 15class InstallCommandTest extends WallabagCoreTestCase
0bf99bb1 16{
3c39f5ac
JB
17 public function setUp()
18 {
19 parent::setUp();
20
21 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) {
22 /*
23 * LOG: statement: CREATE DATABASE "wallabag"
24 * ERROR: source database "template1" is being accessed by other users
25 * DETAIL: There is 1 other session using the database.
26 * STATEMENT: CREATE DATABASE "wallabag"
27 * FATAL: database "wallabag" does not exist
28 *
29 * http://stackoverflow.com/a/14374832/569101
30 */
31 $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.');
32 }
33 }
34
c641baad 35 public static function tearDownAfterClass()
0bf99bb1 36 {
0bf99bb1
J
37 $application = new Application(static::$kernel);
38 $application->setAutoExit(false);
39
4094ea47 40 $code = $application->run(new ArrayInput([
0bf99bb1
J
41 'command' => 'doctrine:fixtures:load',
42 '--no-interaction' => true,
43 '--env' => 'test',
4094ea47 44 ]), new NullOutput());
0bf99bb1
J
45 }
46
47 public function testRunInstallCommand()
48 {
d5027625 49 $application = new Application($this->getClient()->getKernel());
0ee043f7 50 $application->add(new InstallCommandMock());
0bf99bb1
J
51
52 $command = $application->find('wallabag:install');
53
78507d28
JB
54 // We mock the QuestionHelper
55 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
0bf99bb1
J
56 ->disableOriginalConstructor()
57 ->getMock();
78507d28 58 $question->expects($this->any())
0bf99bb1 59 ->method('ask')
78507d28 60 ->will($this->returnValue('yes_'.uniqid('', true)));
0bf99bb1
J
61
62 // We override the standard helper with our mock
78507d28 63 $command->getHelperSet()->set($question, 'question');
0bf99bb1
J
64
65 $tester = new CommandTester($command);
4094ea47 66 $tester->execute([
732c2ad8 67 'command' => $command->getName(),
4094ea47 68 ]);
0bf99bb1 69
637dc4bb
JB
70 $this->assertContains('Checking system requirements.', $tester->getDisplay());
71 $this->assertContains('Setting up database.', $tester->getDisplay());
72 $this->assertContains('Administration setup.', $tester->getDisplay());
73 $this->assertContains('Config setup.', $tester->getDisplay());
0bf99bb1 74 }
c641baad
J
75
76 public function testRunInstallCommandWithReset()
77 {
d5027625 78 $application = new Application($this->getClient()->getKernel());
0ee043f7 79 $application->add(new InstallCommandMock());
c641baad
J
80
81 $command = $application->find('wallabag:install');
82
78507d28
JB
83 // We mock the QuestionHelper
84 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
c641baad
J
85 ->disableOriginalConstructor()
86 ->getMock();
78507d28 87 $question->expects($this->any())
c641baad 88 ->method('ask')
78507d28 89 ->will($this->returnValue('yes_'.uniqid('', true)));
c641baad
J
90
91 // We override the standard helper with our mock
78507d28 92 $command->getHelperSet()->set($question, 'question');
c641baad
J
93
94 $tester = new CommandTester($command);
4094ea47 95 $tester->execute([
c641baad
J
96 'command' => $command->getName(),
97 '--reset' => true,
4094ea47 98 ]);
c641baad 99
637dc4bb
JB
100 $this->assertContains('Checking system requirements.', $tester->getDisplay());
101 $this->assertContains('Setting up database.', $tester->getDisplay());
2a586069 102 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
637dc4bb
JB
103 $this->assertContains('Administration setup.', $tester->getDisplay());
104 $this->assertContains('Config setup.', $tester->getDisplay());
c641baad
J
105
106 // we force to reset everything
d5027625 107 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
c641baad
J
108 }
109
110 public function testRunInstallCommandWithDatabaseRemoved()
111 {
d5027625 112 $application = new Application($this->getClient()->getKernel());
c641baad
J
113 $application->add(new DropDatabaseDoctrineCommand());
114
115 // drop database first, so the install command won't ask to reset things
d5027625 116 $command = $application->find('doctrine:database:drop');
4094ea47 117 $command->run(new ArrayInput([
c641baad
J
118 'command' => 'doctrine:database:drop',
119 '--force' => true,
4094ea47 120 ]), new NullOutput());
c641baad 121
d5027625
JB
122 // start a new application to avoid lagging connexion to pgsql
123 $client = static::createClient();
124 $application = new Application($client->getKernel());
125 $application->add(new InstallCommand());
126
c641baad
J
127 $command = $application->find('wallabag:install');
128
78507d28
JB
129 // We mock the QuestionHelper
130 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
c641baad
J
131 ->disableOriginalConstructor()
132 ->getMock();
78507d28 133 $question->expects($this->any())
c641baad 134 ->method('ask')
78507d28 135 ->will($this->returnValue('yes_'.uniqid('', true)));
c641baad
J
136
137 // We override the standard helper with our mock
78507d28 138 $command->getHelperSet()->set($question, 'question');
c641baad
J
139
140 $tester = new CommandTester($command);
4094ea47 141 $tester->execute([
c641baad 142 'command' => $command->getName(),
4094ea47 143 ]);
c641baad 144
637dc4bb
JB
145 $this->assertContains('Checking system requirements.', $tester->getDisplay());
146 $this->assertContains('Setting up database.', $tester->getDisplay());
147 $this->assertContains('Administration setup.', $tester->getDisplay());
148 $this->assertContains('Config setup.', $tester->getDisplay());
c641baad
J
149
150 // the current database doesn't already exist
151 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
152 }
153
154 public function testRunInstallCommandChooseResetSchema()
155 {
d5027625 156 $application = new Application($this->getClient()->getKernel());
0ee043f7 157 $application->add(new InstallCommandMock());
c641baad
J
158
159 $command = $application->find('wallabag:install');
160
78507d28
JB
161 // We mock the QuestionHelper
162 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
c641baad
J
163 ->disableOriginalConstructor()
164 ->getMock();
165
78507d28
JB
166 $question->expects($this->exactly(3))
167 ->method('ask')
c641baad
J
168 ->will($this->onConsecutiveCalls(
169 false, // don't want to reset the entire database
170 true, // do want to reset the schema
171 false // don't want to create a new user
172 ));
173
174 // We override the standard helper with our mock
78507d28 175 $command->getHelperSet()->set($question, 'question');
c641baad
J
176
177 $tester = new CommandTester($command);
4094ea47 178 $tester->execute([
c641baad 179 'command' => $command->getName(),
4094ea47 180 ]);
c641baad 181
637dc4bb
JB
182 $this->assertContains('Checking system requirements.', $tester->getDisplay());
183 $this->assertContains('Setting up database.', $tester->getDisplay());
184 $this->assertContains('Administration setup.', $tester->getDisplay());
185 $this->assertContains('Config setup.', $tester->getDisplay());
c641baad
J
186
187 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
188 }
189
190 public function testRunInstallCommandChooseNothing()
191 {
d5027625 192 $application = new Application($this->getClient()->getKernel());
c641baad
J
193 $application->add(new InstallCommand());
194 $application->add(new DropDatabaseDoctrineCommand());
195 $application->add(new CreateDatabaseDoctrineCommand());
196
197 // drop database first, so the install command won't ask to reset things
198 $command = new DropDatabaseDoctrineCommand();
199 $command->setApplication($application);
4094ea47 200 $command->run(new ArrayInput([
c641baad
J
201 'command' => 'doctrine:database:drop',
202 '--force' => true,
4094ea47 203 ]), new NullOutput());
c641baad 204
d5027625 205 $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
c641baad
J
206
207 $command = new CreateDatabaseDoctrineCommand();
208 $command->setApplication($application);
4094ea47 209 $command->run(new ArrayInput([
c641baad
J
210 'command' => 'doctrine:database:create',
211 '--env' => 'test',
4094ea47 212 ]), new NullOutput());
c641baad
J
213
214 $command = $application->find('wallabag:install');
215
78507d28
JB
216 // We mock the QuestionHelper
217 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
c641baad
J
218 ->disableOriginalConstructor()
219 ->getMock();
220
78507d28
JB
221 $question->expects($this->exactly(2))
222 ->method('ask')
c641baad
J
223 ->will($this->onConsecutiveCalls(
224 false, // don't want to reset the entire database
225 false // don't want to create a new user
226 ));
227
228 // We override the standard helper with our mock
78507d28 229 $command->getHelperSet()->set($question, 'question');
c641baad
J
230
231 $tester = new CommandTester($command);
4094ea47 232 $tester->execute([
c641baad 233 'command' => $command->getName(),
4094ea47 234 ]);
c641baad 235
637dc4bb
JB
236 $this->assertContains('Checking system requirements.', $tester->getDisplay());
237 $this->assertContains('Setting up database.', $tester->getDisplay());
238 $this->assertContains('Administration setup.', $tester->getDisplay());
239 $this->assertContains('Config setup.', $tester->getDisplay());
c641baad
J
240
241 $this->assertContains('Creating schema', $tester->getDisplay());
242 }
243
244 public function testRunInstallCommandNoInteraction()
245 {
d5027625 246 $application = new Application($this->getClient()->getKernel());
0ee043f7 247 $application->add(new InstallCommandMock());
c641baad
J
248
249 $command = $application->find('wallabag:install');
250
78507d28
JB
251 // We mock the QuestionHelper
252 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
c641baad
J
253 ->disableOriginalConstructor()
254 ->getMock();
78507d28 255 $question->expects($this->any())
c641baad 256 ->method('ask')
78507d28 257 ->will($this->returnValue('yes_'.uniqid('', true)));
c641baad
J
258
259 // We override the standard helper with our mock
78507d28 260 $command->getHelperSet()->set($question, 'question');
c641baad
J
261
262 $tester = new CommandTester($command);
4094ea47 263 $tester->execute([
c641baad
J
264 'command' => $command->getName(),
265 '--no-interaction' => true,
4094ea47 266 ]);
c641baad 267
637dc4bb
JB
268 $this->assertContains('Checking system requirements.', $tester->getDisplay());
269 $this->assertContains('Setting up database.', $tester->getDisplay());
270 $this->assertContains('Administration setup.', $tester->getDisplay());
271 $this->assertContains('Config setup.', $tester->getDisplay());
c641baad 272 }
0bf99bb1 273}