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