3 namespace Tests\Wallabag\CoreBundle\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 Tests\Wallabag\CoreBundle\Mock\InstallCommandMock
;
13 use Tests\Wallabag\CoreBundle\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\'t find a good way to drop current database, skipping.');
36 * Ensure next tests will have a clean database.
38 public static function tearDownAfterClass()
40 $application = new Application(static::$kernel);
41 $application->setAutoExit(false);
43 $application->run(new ArrayInput([
44 'command' => 'doctrine:schema:drop',
45 '--no-interaction' => true,
48 ]), new NullOutput());
50 $application->run(new ArrayInput([
51 'command' => 'doctrine:schema:create',
52 '--no-interaction' => true,
54 ]), new NullOutput());
56 $application->run(new ArrayInput([
57 'command' => 'doctrine:fixtures:load',
58 '--no-interaction' => true,
60 ]), new NullOutput());
63 public function testRunInstallCommand()
65 $application = new Application($this->getClient()->getKernel());
66 $application->add(new InstallCommandMock());
68 $command = $application->find('wallabag:install');
70 $tester = new CommandTester($command);
72 'y', // dropping database
73 'y', // create super admin
74 'username_'.uniqid('', true), // username
75 'password_'.uniqid('', true), // password
76 'email_'.uniqid('', true).'@wallabag.it', // email
79 'command' => $command->getName(),
82 $this->assertContains('Checking system requirements.', $tester->getDisplay());
83 $this->assertContains('Setting up database.', $tester->getDisplay());
84 $this->assertContains('Administration setup.', $tester->getDisplay());
85 $this->assertContains('Config setup.', $tester->getDisplay());
86 $this->assertContains('Run migrations.', $tester->getDisplay());
89 public function testRunInstallCommandWithReset()
91 $application = new Application($this->getClient()->getKernel());
92 $application->add(new InstallCommandMock());
94 $command = $application->find('wallabag:install');
96 $tester = new CommandTester($command);
98 'y', // create super admin
99 'username_'.uniqid('', true), // username
100 'password_'.uniqid('', true), // password
101 'email_'.uniqid('', true).'@wallabag.it', // email
104 'command' => $command->getName(),
108 $this->assertContains('Checking system requirements.', $tester->getDisplay());
109 $this->assertContains('Setting up database.', $tester->getDisplay());
110 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
111 $this->assertContains('Administration setup.', $tester->getDisplay());
112 $this->assertContains('Config setup.', $tester->getDisplay());
113 $this->assertContains('Run migrations.', $tester->getDisplay());
115 // we force to reset everything
116 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
119 public function testRunInstallCommandWithDatabaseRemoved()
121 // skipped SQLite check when database is removed because while testing for the connection,
122 // the driver will create the file (so the database) before testing if database exist
123 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver
) {
124 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.');
127 $application = new Application($this->getClient()->getKernel());
128 $application->add(new DropDatabaseDoctrineCommand());
130 // drop database first, so the install command won't ask to reset things
131 $command = $application->find('doctrine:database:drop');
132 $command->run(new ArrayInput([
133 'command' => 'doctrine:database:drop',
135 ]), new NullOutput());
137 // start a new application to avoid lagging connexion to pgsql
138 $client = static::createClient();
139 $application = new Application($client->getKernel());
140 $application->add(new InstallCommand());
142 $command = $application->find('wallabag:install');
144 $tester = new CommandTester($command);
146 'y', // create super admin
147 'username_'.uniqid('', true), // username
148 'password_'.uniqid('', true), // password
149 'email_'.uniqid('', true).'@wallabag.it', // email
152 'command' => $command->getName(),
155 $this->assertContains('Checking system requirements.', $tester->getDisplay());
156 $this->assertContains('Setting up database.', $tester->getDisplay());
157 $this->assertContains('Administration setup.', $tester->getDisplay());
158 $this->assertContains('Config setup.', $tester->getDisplay());
159 $this->assertContains('Run migrations.', $tester->getDisplay());
161 // the current database doesn't already exist
162 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
165 public function testRunInstallCommandChooseResetSchema()
167 $application = new Application($this->getClient()->getKernel());
168 $application->add(new InstallCommandMock());
170 $command = $application->find('wallabag:install');
172 $tester = new CommandTester($command);
174 'n', // don't want to reset the entire database
175 'y', // do want to reset the schema
176 'n', // don't want to create a new user
179 'command' => $command->getName(),
182 $this->assertContains('Checking system requirements.', $tester->getDisplay());
183 $this->assertContains('Setting up database.', $tester->getDisplay());
184 $this->assertContains('Administration setup.', $tester->getDisplay());
185 $this->assertContains('Config setup.', $tester->getDisplay());
186 $this->assertContains('Run migrations.', $tester->getDisplay());
188 $this->assertContains('Dropping schema and creating schema', $tester->getDisplay());
191 public function testRunInstallCommandChooseNothing()
193 $application = new Application($this->getClient()->getKernel());
194 $application->add(new InstallCommand());
195 $application->add(new DropDatabaseDoctrineCommand());
196 $application->add(new CreateDatabaseDoctrineCommand());
198 // drop database first, so the install command won't ask to reset things
199 $command = new DropDatabaseDoctrineCommand();
200 $command->setApplication($application);
201 $command->run(new ArrayInput([
202 'command' => 'doctrine:database:drop',
204 ]), new NullOutput());
206 $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
208 $command = new CreateDatabaseDoctrineCommand();
209 $command->setApplication($application);
210 $command->run(new ArrayInput([
211 'command' => 'doctrine:database:create',
213 ]), new NullOutput());
215 $command = $application->find('wallabag:install');
217 $tester = new CommandTester($command);
219 'n', // don't want to reset the entire database
220 'n', // don't want to create a new user
223 'command' => $command->getName(),
226 $this->assertContains('Checking system requirements.', $tester->getDisplay());
227 $this->assertContains('Setting up database.', $tester->getDisplay());
228 $this->assertContains('Administration setup.', $tester->getDisplay());
229 $this->assertContains('Config setup.', $tester->getDisplay());
230 $this->assertContains('Run migrations.', $tester->getDisplay());
232 $this->assertContains('Creating schema', $tester->getDisplay());
235 public function testRunInstallCommandNoInteraction()
237 $application = new Application($this->getClient()->getKernel());
238 $application->add(new InstallCommandMock());
240 $command = $application->find('wallabag:install');
242 $tester = new CommandTester($command);
244 'command' => $command->getName(),
246 'interactive' => false,
249 $this->assertContains('Checking system requirements.', $tester->getDisplay());
250 $this->assertContains('Setting up database.', $tester->getDisplay());
251 $this->assertContains('Administration setup.', $tester->getDisplay());
252 $this->assertContains('Config setup.', $tester->getDisplay());
253 $this->assertContains('Run migrations.', $tester->getDisplay());