3 namespace Wallabag\CoreBundle\Tests\Command
;
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
6 use Wallabag\CoreBundle\Command\InstallCommand
;
7 use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock
;
8 use Symfony\Bundle\FrameworkBundle\Console\Application
;
9 use Symfony\Component\Console\Tester\CommandTester
;
10 use Symfony\Component\Console\Input\ArrayInput
;
11 use Symfony\Component\Console\Output\NullOutput
;
12 use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand
;
13 use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand
;
15 class InstallCommandTest
extends WallabagCoreTestCase
17 public static function tearDownAfterClass()
19 $application = new Application(static::$kernel);
20 $application->setAutoExit(false);
22 $code = $application->run(new ArrayInput(array(
23 'command' => 'doctrine:fixtures:load',
24 '--no-interaction' => true,
26 )), new NullOutput());
29 public function testRunInstallCommand()
31 $this->container
= static::$kernel->getContainer();
33 $application = new Application(static::$kernel);
34 $application->add(new InstallCommandMock());
36 $command = $application->find('wallabag:install');
38 // We mock the DialogHelper
39 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
40 ->disableOriginalConstructor()
42 $dialog->expects($this->any())
44 ->will($this->returnValue('test'));
45 $dialog->expects($this->any())
46 ->method('askConfirmation')
47 ->will($this->returnValue(true));
49 // We override the standard helper with our mock
50 $command->getHelperSet()->set($dialog, 'dialog');
52 $tester = new CommandTester($command);
53 $tester->execute(array(
54 'command' => $command->getName(),
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());
63 public function testRunInstallCommandWithReset()
65 $this->container
= static::$kernel->getContainer();
67 $application = new Application(static::$kernel);
68 $application->add(new InstallCommandMock());
70 $command = $application->find('wallabag:install');
72 // We mock the DialogHelper
73 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
74 ->disableOriginalConstructor()
76 $dialog->expects($this->any())
78 ->will($this->returnValue('test'));
79 $dialog->expects($this->any())
80 ->method('askConfirmation')
81 ->will($this->returnValue(true));
83 // We override the standard helper with our mock
84 $command->getHelperSet()->set($dialog, 'dialog');
86 $tester = new CommandTester($command);
87 $tester->execute(array(
88 'command' => $command->getName(),
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());
97 // we force to reset everything
98 $this->assertContains('Droping database, creating database and schema', $tester->getDisplay());
102 * @group command-doctrine
104 public function testRunInstallCommandWithDatabaseRemoved()
106 $this->container
= static::$kernel->getContainer();
108 $application = new Application(static::$kernel);
109 $application->add(new InstallCommand());
110 $application->add(new DropDatabaseDoctrineCommand());
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',
118 )), new NullOutput());
120 $command = $application->find('wallabag:install');
122 // We mock the DialogHelper
123 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
124 ->disableOriginalConstructor()
126 $dialog->expects($this->any())
128 ->will($this->returnValue('test'));
129 $dialog->expects($this->any())
130 ->method('askConfirmation')
131 ->will($this->returnValue(true));
133 // We override the standard helper with our mock
134 $command->getHelperSet()->set($dialog, 'dialog');
136 $tester = new CommandTester($command);
137 $tester->execute(array(
138 'command' => $command->getName(),
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());
146 // the current database doesn't already exist
147 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
150 public function testRunInstallCommandChooseResetSchema()
152 $this->container
= static::$kernel->getContainer();
154 $application = new Application(static::$kernel);
155 $application->add(new InstallCommandMock());
157 $command = $application->find('wallabag:install');
159 // We mock the DialogHelper
160 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
161 ->disableOriginalConstructor()
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
172 // We override the standard helper with our mock
173 $command->getHelperSet()->set($dialog, 'dialog');
175 $tester = new CommandTester($command);
176 $tester->execute(array(
177 'command' => $command->getName(),
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());
185 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
189 * @group command-doctrine
191 public function testRunInstallCommandChooseNothing()
193 $this->container
= static::$kernel->getContainer();
195 $application = new Application(static::$kernel);
196 $application->add(new InstallCommand());
197 $application->add(new DropDatabaseDoctrineCommand());
198 $application->add(new CreateDatabaseDoctrineCommand());
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',
206 )), new NullOutput());
208 $this->container
->get('doctrine')->getManager()->getConnection()->close();
210 $command = new CreateDatabaseDoctrineCommand();
211 $command->setApplication($application);
212 $command->run(new ArrayInput(array(
213 'command' => 'doctrine:database:create',
215 )), new NullOutput());
217 $command = $application->find('wallabag:install');
219 // We mock the DialogHelper
220 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
221 ->disableOriginalConstructor()
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
231 // We override the standard helper with our mock
232 $command->getHelperSet()->set($dialog, 'dialog');
234 $tester = new CommandTester($command);
235 $tester->execute(array(
236 'command' => $command->getName(),
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());
244 $this->assertContains('Creating schema', $tester->getDisplay());
247 public function testRunInstallCommandNoInteraction()
249 $this->container
= static::$kernel->getContainer();
251 $application = new Application(static::$kernel);
252 $application->add(new InstallCommandMock());
254 $command = $application->find('wallabag:install');
256 // We mock the DialogHelper
257 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
258 ->disableOriginalConstructor()
260 $dialog->expects($this->any())
262 ->will($this->returnValue('test'));
263 $dialog->expects($this->any())
264 ->method('askConfirmation')
265 ->will($this->returnValue(true));
267 // We override the standard helper with our mock
268 $command->getHelperSet()->set($dialog, 'dialog');
270 $tester = new CommandTester($command);
271 $tester->execute(array(
272 'command' => $command->getName(),
273 '--no-interaction' => true,
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());