3 namespace Wallabag\CoreBundle\Tests\Command
;
5 use Wallabag\CoreBundle\Tests\WallabagTestCase
;
6 use Wallabag\CoreBundle\Command\InstallCommand
;
7 use Symfony\Bundle\FrameworkBundle\Console\Application
;
8 use Symfony\Component\Console\Tester\CommandTester
;
9 use Symfony\Component\Console\Input\ArrayInput
;
10 use Symfony\Component\Console\Output\NullOutput
;
11 use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand
;
12 use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand
;
14 class InstallCommandTest
extends WallabagTestCase
16 public static function tearDownAfterClass()
18 $application = new Application(static::$kernel);
19 $application->setAutoExit(false);
21 $code = $application->run(new ArrayInput(array(
22 'command' => 'doctrine:fixtures:load',
23 '--no-interaction' => true,
25 )), new NullOutput());
28 public function testRunInstallCommand()
30 $this->container
= static::$kernel->getContainer();
32 $application = new Application(static::$kernel);
33 $application->add(new InstallCommand());
35 $command = $application->find('wallabag:install');
37 // We mock the DialogHelper
38 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
39 ->disableOriginalConstructor()
41 $dialog->expects($this->any())
43 ->will($this->returnValue('test'));
44 $dialog->expects($this->any())
45 ->method('askConfirmation')
46 ->will($this->returnValue(true));
48 // We override the standard helper with our mock
49 $command->getHelperSet()->set($dialog, 'dialog');
51 $tester = new CommandTester($command);
52 $tester->execute(array(
53 'command' => $command->getName(),
56 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
57 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
58 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
59 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
62 public function testRunInstallCommandWithReset()
64 $this->container
= static::$kernel->getContainer();
66 $application = new Application(static::$kernel);
67 $application->add(new InstallCommand());
69 $command = $application->find('wallabag:install');
71 // We mock the DialogHelper
72 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
73 ->disableOriginalConstructor()
75 $dialog->expects($this->any())
77 ->will($this->returnValue('test'));
78 $dialog->expects($this->any())
79 ->method('askConfirmation')
80 ->will($this->returnValue(true));
82 // We override the standard helper with our mock
83 $command->getHelperSet()->set($dialog, 'dialog');
85 $tester = new CommandTester($command);
86 $tester->execute(array(
87 'command' => $command->getName(),
91 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
92 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
93 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
94 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
96 // we force to reset everything
97 $this->assertContains('Droping database, creating database and schema', $tester->getDisplay());
100 public function testRunInstallCommandWithDatabaseRemoved()
102 $this->container
= static::$kernel->getContainer();
104 $application = new Application(static::$kernel);
105 $application->add(new InstallCommand());
106 $application->add(new DropDatabaseDoctrineCommand());
108 // drop database first, so the install command won't ask to reset things
109 $command = new DropDatabaseDoctrineCommand();
110 $command->setApplication($application);
111 $command->run(new ArrayInput(array(
112 'command' => 'doctrine:database:drop',
114 )), new NullOutput());
116 $command = $application->find('wallabag:install');
118 // We mock the DialogHelper
119 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
120 ->disableOriginalConstructor()
122 $dialog->expects($this->any())
124 ->will($this->returnValue('test'));
125 $dialog->expects($this->any())
126 ->method('askConfirmation')
127 ->will($this->returnValue(true));
129 // We override the standard helper with our mock
130 $command->getHelperSet()->set($dialog, 'dialog');
132 $tester = new CommandTester($command);
133 $tester->execute(array(
134 'command' => $command->getName(),
137 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
138 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
139 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
140 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
142 // the current database doesn't already exist
143 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
146 public function testRunInstallCommandChooseResetSchema()
148 $this->container
= static::$kernel->getContainer();
150 $application = new Application(static::$kernel);
151 $application->add(new InstallCommand());
153 $command = $application->find('wallabag:install');
155 // We mock the DialogHelper
156 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
157 ->disableOriginalConstructor()
160 $dialog->expects($this->exactly(3))
161 ->method('askConfirmation')
162 ->will($this->onConsecutiveCalls(
163 false, // don't want to reset the entire database
164 true, // do want to reset the schema
165 false // don't want to create a new user
168 // We override the standard helper with our mock
169 $command->getHelperSet()->set($dialog, 'dialog');
171 $tester = new CommandTester($command);
172 $tester->execute(array(
173 'command' => $command->getName(),
176 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
177 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
178 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
179 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
181 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
184 public function testRunInstallCommandChooseNothing()
186 $this->container
= static::$kernel->getContainer();
188 $application = new Application(static::$kernel);
189 $application->add(new InstallCommand());
190 $application->add(new DropDatabaseDoctrineCommand());
191 $application->add(new CreateDatabaseDoctrineCommand());
193 // drop database first, so the install command won't ask to reset things
194 $command = new DropDatabaseDoctrineCommand();
195 $command->setApplication($application);
196 $command->run(new ArrayInput(array(
197 'command' => 'doctrine:database:drop',
199 )), new NullOutput());
201 $this->container
->get('doctrine')->getManager()->getConnection()->close();
203 $command = new CreateDatabaseDoctrineCommand();
204 $command->setApplication($application);
205 $command->run(new ArrayInput(array(
206 'command' => 'doctrine:database:create',
208 )), new NullOutput());
210 $command = $application->find('wallabag:install');
212 // We mock the DialogHelper
213 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
214 ->disableOriginalConstructor()
217 $dialog->expects($this->exactly(2))
218 ->method('askConfirmation')
219 ->will($this->onConsecutiveCalls(
220 false, // don't want to reset the entire database
221 false // don't want to create a new user
224 // We override the standard helper with our mock
225 $command->getHelperSet()->set($dialog, 'dialog');
227 $tester = new CommandTester($command);
228 $tester->execute(array(
229 'command' => $command->getName(),
232 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
233 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
234 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
235 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());
237 $this->assertContains('Creating schema', $tester->getDisplay());
240 public function testRunInstallCommandNoInteraction()
242 $this->container
= static::$kernel->getContainer();
244 $application = new Application(static::$kernel);
245 $application->add(new InstallCommand());
247 $command = $application->find('wallabag:install');
249 // We mock the DialogHelper
250 $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
251 ->disableOriginalConstructor()
253 $dialog->expects($this->any())
255 ->will($this->returnValue('test'));
256 $dialog->expects($this->any())
257 ->method('askConfirmation')
258 ->will($this->returnValue(true));
260 // We override the standard helper with our mock
261 $command->getHelperSet()->set($dialog, 'dialog');
263 $tester = new CommandTester($command);
264 $tester->execute(array(
265 'command' => $command->getName(),
266 '--no-interaction' => true,
269 $this->assertContains('Step 1 of 4. Checking system requirements.', $tester->getDisplay());
270 $this->assertContains('Step 2 of 4. Setting up database.', $tester->getDisplay());
271 $this->assertContains('Step 3 of 4. Administration setup.', $tester->getDisplay());
272 $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay());