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