3 namespace Wallabag\CoreBundle\Tests\Command
;
5 use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand
;
6 use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand
;
7 use Symfony\Bundle\FrameworkBundle\Console\Application
;
8 use Symfony\Component\Console\Input\ArrayInput
;
9 use Symfony\Component\Console\Output\NullOutput
;
10 use Symfony\Component\Console\Tester\CommandTester
;
11 use Wallabag\CoreBundle\Command\InstallCommand
;
12 use Wallabag\CoreBundle\Tests\Mock\InstallCommandMock
;
13 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
15 class InstallCommandTest
extends WallabagCoreTestCase
17 public function setUp()
21 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver
) {
23 * LOG: statement: CREATE DATABASE "wallabag"
24 * ERROR: source database "template1" is being accessed by other users
25 * DETAIL: There is 1 other session using the database.
26 * STATEMENT: CREATE DATABASE "wallabag"
27 * FATAL: database "wallabag" does not exist
29 * http://stackoverflow.com/a/14374832/569101
31 $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.');
35 public static function tearDownAfterClass()
37 $application = new Application(static::$kernel);
38 $application->setAutoExit(false);
40 $code = $application->run(new ArrayInput([
41 'command' => 'doctrine:fixtures:load',
42 '--no-interaction' => true,
44 ]), new NullOutput());
47 public function testRunInstallCommand()
49 $application = new Application($this->getClient()->getKernel());
50 $application->add(new InstallCommandMock());
52 $command = $application->find('wallabag:install');
54 // We mock the QuestionHelper
55 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
56 ->disableOriginalConstructor()
58 $question->expects($this->any())
60 ->will($this->returnValue('yes_'.uniqid('', true)));
62 // We override the standard helper with our mock
63 $command->getHelperSet()->set($question, 'question');
65 $tester = new CommandTester($command);
67 'command' => $command->getName(),
70 $this->assertContains('Checking system requirements.', $tester->getDisplay());
71 $this->assertContains('Setting up database.', $tester->getDisplay());
72 $this->assertContains('Administration setup.', $tester->getDisplay());
73 $this->assertContains('Config setup.', $tester->getDisplay());
74 $this->assertContains('Installing assets.', $tester->getDisplay());
77 public function testRunInstallCommandWithReset()
79 $application = new Application($this->getClient()->getKernel());
80 $application->add(new InstallCommandMock());
82 $command = $application->find('wallabag:install');
84 // We mock the QuestionHelper
85 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
86 ->disableOriginalConstructor()
88 $question->expects($this->any())
90 ->will($this->returnValue('yes_'.uniqid('', true)));
92 // We override the standard helper with our mock
93 $command->getHelperSet()->set($question, 'question');
95 $tester = new CommandTester($command);
97 'command' => $command->getName(),
101 $this->assertContains('Checking system requirements.', $tester->getDisplay());
102 $this->assertContains('Setting up database.', $tester->getDisplay());
103 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
104 $this->assertContains('Administration setup.', $tester->getDisplay());
105 $this->assertContains('Config setup.', $tester->getDisplay());
106 $this->assertContains('Installing assets.', $tester->getDisplay());
108 // we force to reset everything
109 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
112 public function testRunInstallCommandWithDatabaseRemoved()
114 $application = new Application($this->getClient()->getKernel());
115 $application->add(new DropDatabaseDoctrineCommand());
117 // drop database first, so the install command won't ask to reset things
118 $command = $application->find('doctrine:database:drop');
119 $command->run(new ArrayInput([
120 'command' => 'doctrine:database:drop',
122 ]), new NullOutput());
124 // start a new application to avoid lagging connexion to pgsql
125 $client = static::createClient();
126 $application = new Application($client->getKernel());
127 $application->add(new InstallCommand());
129 $command = $application->find('wallabag:install');
131 // We mock the QuestionHelper
132 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
133 ->disableOriginalConstructor()
135 $question->expects($this->any())
137 ->will($this->returnValue('yes_'.uniqid('', true)));
139 // We override the standard helper with our mock
140 $command->getHelperSet()->set($question, 'question');
142 $tester = new CommandTester($command);
144 'command' => $command->getName(),
147 $this->assertContains('Checking system requirements.', $tester->getDisplay());
148 $this->assertContains('Setting up database.', $tester->getDisplay());
149 $this->assertContains('Administration setup.', $tester->getDisplay());
150 $this->assertContains('Config setup.', $tester->getDisplay());
151 $this->assertContains('Installing assets.', $tester->getDisplay());
153 // the current database doesn't already exist
154 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
157 public function testRunInstallCommandChooseResetSchema()
159 $application = new Application($this->getClient()->getKernel());
160 $application->add(new InstallCommandMock());
162 $command = $application->find('wallabag:install');
164 // We mock the QuestionHelper
165 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
166 ->disableOriginalConstructor()
169 $question->expects($this->exactly(3))
171 ->will($this->onConsecutiveCalls(
172 false, // don't want to reset the entire database
173 true, // do want to reset the schema
174 false // don't want to create a new user
177 // We override the standard helper with our mock
178 $command->getHelperSet()->set($question, 'question');
180 $tester = new CommandTester($command);
182 'command' => $command->getName(),
185 $this->assertContains('Checking system requirements.', $tester->getDisplay());
186 $this->assertContains('Setting up database.', $tester->getDisplay());
187 $this->assertContains('Administration setup.', $tester->getDisplay());
188 $this->assertContains('Config setup.', $tester->getDisplay());
189 $this->assertContains('Installing assets.', $tester->getDisplay());
191 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
194 public function testRunInstallCommandChooseNothing()
196 $application = new Application($this->getClient()->getKernel());
197 $application->add(new InstallCommand());
198 $application->add(new DropDatabaseDoctrineCommand());
199 $application->add(new CreateDatabaseDoctrineCommand());
201 // drop database first, so the install command won't ask to reset things
202 $command = new DropDatabaseDoctrineCommand();
203 $command->setApplication($application);
204 $command->run(new ArrayInput([
205 'command' => 'doctrine:database:drop',
207 ]), new NullOutput());
209 $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
211 $command = new CreateDatabaseDoctrineCommand();
212 $command->setApplication($application);
213 $command->run(new ArrayInput([
214 'command' => 'doctrine:database:create',
216 ]), new NullOutput());
218 $command = $application->find('wallabag:install');
220 // We mock the QuestionHelper
221 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
222 ->disableOriginalConstructor()
225 $question->expects($this->exactly(2))
227 ->will($this->onConsecutiveCalls(
228 false, // don't want to reset the entire database
229 false // don't want to create a new user
232 // We override the standard helper with our mock
233 $command->getHelperSet()->set($question, 'question');
235 $tester = new CommandTester($command);
237 'command' => $command->getName(),
240 $this->assertContains('Checking system requirements.', $tester->getDisplay());
241 $this->assertContains('Setting up database.', $tester->getDisplay());
242 $this->assertContains('Administration setup.', $tester->getDisplay());
243 $this->assertContains('Config setup.', $tester->getDisplay());
244 $this->assertContains('Installing assets.', $tester->getDisplay());
246 $this->assertContains('Creating schema', $tester->getDisplay());
249 public function testRunInstallCommandNoInteraction()
251 $application = new Application($this->getClient()->getKernel());
252 $application->add(new InstallCommandMock());
254 $command = $application->find('wallabag:install');
256 // We mock the QuestionHelper
257 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
258 ->disableOriginalConstructor()
260 $question->expects($this->any())
262 ->will($this->returnValue('yes_'.uniqid('', true)));
264 // We override the standard helper with our mock
265 $command->getHelperSet()->set($question, 'question');
267 $tester = new CommandTester($command);
269 'command' => $command->getName(),
270 '--no-interaction' => true,
273 $this->assertContains('Checking system requirements.', $tester->getDisplay());
274 $this->assertContains('Setting up database.', $tester->getDisplay());
275 $this->assertContains('Administration setup.', $tester->getDisplay());
276 $this->assertContains('Config setup.', $tester->getDisplay());
277 $this->assertContains('Installing assets.', $tester->getDisplay());