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 QuestionHelper
39 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
40 ->disableOriginalConstructor()
42 $question->expects($this->any())
44 ->will($this->returnValue('yes_'.uniqid('', true)));
46 // We override the standard helper with our mock
47 $command->getHelperSet()->set($question, 'question');
49 $tester = new CommandTester($command);
50 $tester->execute(array(
51 'command' => $command->getName(),
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());
60 public function testRunInstallCommandWithReset()
62 $this->container
= static::$kernel->getContainer();
64 $application = new Application(static::$kernel);
65 $application->add(new InstallCommandMock());
67 $command = $application->find('wallabag:install');
69 // We mock the QuestionHelper
70 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
71 ->disableOriginalConstructor()
73 $question->expects($this->any())
75 ->will($this->returnValue('yes_'.uniqid('', true)));
77 // We override the standard helper with our mock
78 $command->getHelperSet()->set($question, 'question');
80 $tester = new CommandTester($command);
81 $tester->execute(array(
82 'command' => $command->getName(),
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());
91 // we force to reset everything
92 $this->assertContains('Droping database, creating database and schema', $tester->getDisplay());
96 * @group command-doctrine
98 public function testRunInstallCommandWithDatabaseRemoved()
100 $this->container
= static::$kernel->getContainer();
102 $application = new Application(static::$kernel);
103 $application->add(new InstallCommand());
104 $application->add(new DropDatabaseDoctrineCommand());
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',
112 )), new NullOutput());
114 $command = $application->find('wallabag:install');
116 // We mock the QuestionHelper
117 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
118 ->disableOriginalConstructor()
120 $question->expects($this->any())
122 ->will($this->returnValue('yes_'.uniqid('', true)));
124 // We override the standard helper with our mock
125 $command->getHelperSet()->set($question, 'question');
127 $tester = new CommandTester($command);
128 $tester->execute(array(
129 'command' => $command->getName(),
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());
137 // the current database doesn't already exist
138 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
141 public function testRunInstallCommandChooseResetSchema()
143 $this->container
= static::$kernel->getContainer();
145 $application = new Application(static::$kernel);
146 $application->add(new InstallCommandMock());
148 $command = $application->find('wallabag:install');
150 // We mock the QuestionHelper
151 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
152 ->disableOriginalConstructor()
155 $question->expects($this->exactly(3))
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
163 // We override the standard helper with our mock
164 $command->getHelperSet()->set($question, 'question');
166 $tester = new CommandTester($command);
167 $tester->execute(array(
168 'command' => $command->getName(),
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());
176 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
180 * @group command-doctrine
182 public function testRunInstallCommandChooseNothing()
184 $this->container
= static::$kernel->getContainer();
186 $application = new Application(static::$kernel);
187 $application->add(new InstallCommand());
188 $application->add(new DropDatabaseDoctrineCommand());
189 $application->add(new CreateDatabaseDoctrineCommand());
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',
197 )), new NullOutput());
199 $this->container
->get('doctrine')->getManager()->getConnection()->close();
201 $command = new CreateDatabaseDoctrineCommand();
202 $command->setApplication($application);
203 $command->run(new ArrayInput(array(
204 'command' => 'doctrine:database:create',
206 )), new NullOutput());
208 $command = $application->find('wallabag:install');
210 // We mock the QuestionHelper
211 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
212 ->disableOriginalConstructor()
215 $question->expects($this->exactly(2))
217 ->will($this->onConsecutiveCalls(
218 false, // don't want to reset the entire database
219 false // don't want to create a new user
222 // We override the standard helper with our mock
223 $command->getHelperSet()->set($question, 'question');
225 $tester = new CommandTester($command);
226 $tester->execute(array(
227 'command' => $command->getName(),
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());
235 $this->assertContains('Creating schema', $tester->getDisplay());
238 public function testRunInstallCommandNoInteraction()
240 $this->container
= static::$kernel->getContainer();
242 $application = new Application(static::$kernel);
243 $application->add(new InstallCommandMock());
245 $command = $application->find('wallabag:install');
247 // We mock the QuestionHelper
248 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
249 ->disableOriginalConstructor()
251 $question->expects($this->any())
253 ->will($this->returnValue('yes_'.uniqid('', true)));
255 // We override the standard helper with our mock
256 $command->getHelperSet()->set($question, 'question');
258 $tester = new CommandTester($command);
259 $tester->execute(array(
260 'command' => $command->getName(),
261 '--no-interaction' => true,
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());