diff options
3 files changed, 48 insertions, 30 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 8b702c95..85c4ee90 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -111,14 +111,17 @@ class InstallCommand extends ContainerAwareCommand | |||
111 | 111 | ||
112 | // user want to reset everything? Don't care about what is already here | 112 | // user want to reset everything? Don't care about what is already here |
113 | if (true === $this->defaultInput->getOption('reset')) { | 113 | if (true === $this->defaultInput->getOption('reset')) { |
114 | $this->defaultOutput->writeln('Droping database, creating database and schema'); | 114 | $this->defaultOutput->writeln('Droping database, creating database and schema, clearing the cache'); |
115 | 115 | ||
116 | $this | 116 | $this |
117 | ->runCommand('doctrine:database:drop', array('--force' => true)) | 117 | ->runCommand('doctrine:database:drop', array('--force' => true)) |
118 | ->runCommand('doctrine:database:create') | 118 | ->runCommand('doctrine:database:create') |
119 | ->runCommand('doctrine:schema:create') | 119 | ->runCommand('doctrine:schema:create') |
120 | ->runCommand('cache:clear') | ||
120 | ; | 121 | ; |
121 | 122 | ||
123 | $this->defaultOutput->writeln(''); | ||
124 | |||
122 | return $this; | 125 | return $this; |
123 | } | 126 | } |
124 | 127 | ||
@@ -131,6 +134,8 @@ class InstallCommand extends ContainerAwareCommand | |||
131 | ->runCommand('cache:clear') | 134 | ->runCommand('cache:clear') |
132 | ; | 135 | ; |
133 | 136 | ||
137 | $this->defaultOutput->writeln(''); | ||
138 | |||
134 | return $this; | 139 | return $this; |
135 | } | 140 | } |
136 | 141 | ||
diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index e98dd202..e3ff47c0 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php | |||
@@ -28,9 +28,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
28 | 28 | ||
29 | public function testRunInstallCommand() | 29 | public function testRunInstallCommand() |
30 | { | 30 | { |
31 | $this->container = static::$kernel->getContainer(); | 31 | $application = new Application($this->getClient()->getKernel()); |
32 | |||
33 | $application = new Application(static::$kernel); | ||
34 | $application->add(new InstallCommandMock()); | 32 | $application->add(new InstallCommandMock()); |
35 | 33 | ||
36 | $command = $application->find('wallabag:install'); | 34 | $command = $application->find('wallabag:install'); |
@@ -59,9 +57,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
59 | 57 | ||
60 | public function testRunInstallCommandWithReset() | 58 | public function testRunInstallCommandWithReset() |
61 | { | 59 | { |
62 | $this->container = static::$kernel->getContainer(); | 60 | $application = new Application($this->getClient()->getKernel()); |
63 | |||
64 | $application = new Application(static::$kernel); | ||
65 | $application->add(new InstallCommandMock()); | 61 | $application->add(new InstallCommandMock()); |
66 | 62 | ||
67 | $command = $application->find('wallabag:install'); | 63 | $command = $application->find('wallabag:install'); |
@@ -89,28 +85,39 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
89 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); | 85 | $this->assertContains('Step 4 of 4. Installing assets.', $tester->getDisplay()); |
90 | 86 | ||
91 | // we force to reset everything | 87 | // we force to reset everything |
92 | $this->assertContains('Droping database, creating database and schema', $tester->getDisplay()); | 88 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
93 | } | 89 | } |
94 | 90 | ||
95 | /** | ||
96 | * @group command-doctrine | ||
97 | */ | ||
98 | public function testRunInstallCommandWithDatabaseRemoved() | 91 | public function testRunInstallCommandWithDatabaseRemoved() |
99 | { | 92 | { |
100 | $this->container = static::$kernel->getContainer(); | 93 | if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { |
101 | 94 | /** | |
102 | $application = new Application(static::$kernel); | 95 | * LOG: statement: CREATE DATABASE "wallabag" |
103 | $application->add(new InstallCommand()); | 96 | * ERROR: source database "template1" is being accessed by other users |
97 | * DETAIL: There is 1 other session using the database. | ||
98 | * STATEMENT: CREATE DATABASE "wallabag" | ||
99 | * FATAL: database "wallabag" does not exist | ||
100 | * | ||
101 | * http://stackoverflow.com/a/14374832/569101 | ||
102 | */ | ||
103 | $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); | ||
104 | } | ||
105 | |||
106 | $application = new Application($this->getClient()->getKernel()); | ||
104 | $application->add(new DropDatabaseDoctrineCommand()); | 107 | $application->add(new DropDatabaseDoctrineCommand()); |
105 | 108 | ||
106 | // drop database first, so the install command won't ask to reset things | 109 | // drop database first, so the install command won't ask to reset things |
107 | $command = new DropDatabaseDoctrineCommand(); | 110 | $command = $application->find('doctrine:database:drop'); |
108 | $command->setApplication($application); | ||
109 | $command->run(new ArrayInput(array( | 111 | $command->run(new ArrayInput(array( |
110 | 'command' => 'doctrine:database:drop', | 112 | 'command' => 'doctrine:database:drop', |
111 | '--force' => true, | 113 | '--force' => true, |
112 | )), new NullOutput()); | 114 | )), new NullOutput()); |
113 | 115 | ||
116 | // start a new application to avoid lagging connexion to pgsql | ||
117 | $client = static::createClient(); | ||
118 | $application = new Application($client->getKernel()); | ||
119 | $application->add(new InstallCommand()); | ||
120 | |||
114 | $command = $application->find('wallabag:install'); | 121 | $command = $application->find('wallabag:install'); |
115 | 122 | ||
116 | // We mock the QuestionHelper | 123 | // We mock the QuestionHelper |
@@ -140,9 +147,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
140 | 147 | ||
141 | public function testRunInstallCommandChooseResetSchema() | 148 | public function testRunInstallCommandChooseResetSchema() |
142 | { | 149 | { |
143 | $this->container = static::$kernel->getContainer(); | 150 | $application = new Application($this->getClient()->getKernel()); |
144 | |||
145 | $application = new Application(static::$kernel); | ||
146 | $application->add(new InstallCommandMock()); | 151 | $application->add(new InstallCommandMock()); |
147 | 152 | ||
148 | $command = $application->find('wallabag:install'); | 153 | $command = $application->find('wallabag:install'); |
@@ -176,14 +181,22 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
176 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); | 181 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); |
177 | } | 182 | } |
178 | 183 | ||
179 | /** | ||
180 | * @group command-doctrine | ||
181 | */ | ||
182 | public function testRunInstallCommandChooseNothing() | 184 | public function testRunInstallCommandChooseNothing() |
183 | { | 185 | { |
184 | $this->container = static::$kernel->getContainer(); | 186 | if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceOf \Doctrine\DBAL\Driver\PDOPgSql\Driver) { |
185 | 187 | /** | |
186 | $application = new Application(static::$kernel); | 188 | * LOG: statement: CREATE DATABASE "wallabag" |
189 | * ERROR: source database "template1" is being accessed by other users | ||
190 | * DETAIL: There is 1 other session using the database. | ||
191 | * STATEMENT: CREATE DATABASE "wallabag" | ||
192 | * FATAL: database "wallabag" does not exist | ||
193 | * | ||
194 | * http://stackoverflow.com/a/14374832/569101 | ||
195 | */ | ||
196 | $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); | ||
197 | } | ||
198 | |||
199 | $application = new Application($this->getClient()->getKernel()); | ||
187 | $application->add(new InstallCommand()); | 200 | $application->add(new InstallCommand()); |
188 | $application->add(new DropDatabaseDoctrineCommand()); | 201 | $application->add(new DropDatabaseDoctrineCommand()); |
189 | $application->add(new CreateDatabaseDoctrineCommand()); | 202 | $application->add(new CreateDatabaseDoctrineCommand()); |
@@ -196,7 +209,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
196 | '--force' => true, | 209 | '--force' => true, |
197 | )), new NullOutput()); | 210 | )), new NullOutput()); |
198 | 211 | ||
199 | $this->container->get('doctrine')->getManager()->getConnection()->close(); | 212 | $this->getClient()->getContainer()->get('doctrine')->getConnection()->close(); |
200 | 213 | ||
201 | $command = new CreateDatabaseDoctrineCommand(); | 214 | $command = new CreateDatabaseDoctrineCommand(); |
202 | $command->setApplication($application); | 215 | $command->setApplication($application); |
@@ -237,9 +250,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
237 | 250 | ||
238 | public function testRunInstallCommandNoInteraction() | 251 | public function testRunInstallCommandNoInteraction() |
239 | { | 252 | { |
240 | $this->container = static::$kernel->getContainer(); | 253 | $application = new Application($this->getClient()->getKernel()); |
241 | |||
242 | $application = new Application(static::$kernel); | ||
243 | $application->add(new InstallCommandMock()); | 254 | $application->add(new InstallCommandMock()); |
244 | 255 | ||
245 | $command = $application->find('wallabag:install'); | 256 | $command = $application->find('wallabag:install'); |
diff --git a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php index e5096528..ce3cabe8 100644 --- a/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php +++ b/src/Wallabag/CoreBundle/Tests/WallabagCoreTestCase.php | |||
@@ -15,6 +15,8 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
15 | 15 | ||
16 | public function setUp() | 16 | public function setUp() |
17 | { | 17 | { |
18 | parent::setUp(); | ||
19 | |||
18 | $this->client = static::createClient(); | 20 | $this->client = static::createClient(); |
19 | } | 21 | } |
20 | 22 | ||