aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command/InstallCommandTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php185
1 files changed, 80 insertions, 105 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 1bfd41d5..94fc0b94 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -2,8 +2,11 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Command; 3namespace Tests\Wallabag\CoreBundle\Command;
4 4
5use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
5use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; 6use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
6use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; 7use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
8use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
9use Doctrine\DBAL\Platforms\SqlitePlatform;
7use Symfony\Bundle\FrameworkBundle\Console\Application; 10use Symfony\Bundle\FrameworkBundle\Console\Application;
8use Symfony\Component\Console\Input\ArrayInput; 11use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Output\NullOutput; 12use Symfony\Component\Console\Output\NullOutput;
@@ -18,7 +21,9 @@ class InstallCommandTest extends WallabagCoreTestCase
18 { 21 {
19 parent::setUp(); 22 parent::setUp();
20 23
21 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { 24 /** @var \Doctrine\DBAL\Connection $connection */
25 $connection = $this->getClient()->getContainer()->get('doctrine')->getConnection();
26 if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
22 /* 27 /*
23 * LOG: statement: CREATE DATABASE "wallabag" 28 * LOG: statement: CREATE DATABASE "wallabag"
24 * ERROR: source database "template1" is being accessed by other users 29 * ERROR: source database "template1" is being accessed by other users
@@ -30,34 +35,44 @@ class InstallCommandTest extends WallabagCoreTestCase
30 */ 35 */
31 $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); 36 $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.');
32 } 37 }
33 }
34 38
35 /** 39 if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
36 * Ensure next tests will have a clean database. 40 // Environnement variable useful only for sqlite to avoid the error "attempt to write a readonly database"
37 */ 41 // We can't define always this environnement variable because pdo_mysql seems to use it
38 public static function tearDownAfterClass() 42 // and we have the error:
39 { 43 // SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
40 $application = new Application(static::$kernel); 44 // check the manual that corresponds to your MariaDB server version for the right syntax to use
41 $application->setAutoExit(false); 45 // near '/tmp/wallabag_testTYj1kp' at line 1
46 $databasePath = tempnam(sys_get_temp_dir(), 'wallabag_test');
47 putenv("TEST_DATABASE_PATH=$databasePath");
48
49 // The environnement has been changed, recreate the client in order to update connection
50 parent::setUp();
51 }
42 52
43 $application->run(new ArrayInput([ 53 // disable doctrine-test-bundle
44 'command' => 'doctrine:schema:drop', 54 StaticDriver::setKeepStaticConnections(false);
45 '--no-interaction' => true,
46 '--force' => true,
47 '--env' => 'test',
48 ]), new NullOutput());
49 55
50 $application->run(new ArrayInput([ 56 $this->resetDatabase($this->getClient());
51 'command' => 'doctrine:schema:create', 57 }
52 '--no-interaction' => true,
53 '--env' => 'test',
54 ]), new NullOutput());
55 58
56 $application->run(new ArrayInput([ 59 public function tearDown()
57 'command' => 'doctrine:fixtures:load', 60 {
58 '--no-interaction' => true, 61 $databasePath = getenv('TEST_DATABASE_PATH');
59 '--env' => 'test', 62 // Remove variable environnement
60 ]), new NullOutput()); 63 putenv('TEST_DATABASE_PATH');
64 if ($databasePath && file_exists($databasePath)) {
65 unlink($databasePath);
66 } else {
67 // Create a new client to avoid the error:
68 // Transaction commit failed because the transaction has been marked for rollback only.
69 $client = static::createClient();
70 $this->resetDatabase($client);
71 }
72
73 // enable doctrine-test-bundle
74 StaticDriver::setKeepStaticConnections(true);
75 parent::tearDown();
61 } 76 }
62 77
63 public function testRunInstallCommand() 78 public function testRunInstallCommand()
@@ -67,18 +82,14 @@ class InstallCommandTest extends WallabagCoreTestCase
67 82
68 $command = $application->find('wallabag:install'); 83 $command = $application->find('wallabag:install');
69 84
70 // We mock the QuestionHelper
71 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
72 ->disableOriginalConstructor()
73 ->getMock();
74 $question->expects($this->any())
75 ->method('ask')
76 ->will($this->returnValue('yes_'.uniqid('', true)));
77
78 // We override the standard helper with our mock
79 $command->getHelperSet()->set($question, 'question');
80
81 $tester = new CommandTester($command); 85 $tester = new CommandTester($command);
86 $tester->setInputs([
87 'y', // dropping database
88 'y', // create super admin
89 'username_'.uniqid('', true), // username
90 'password_'.uniqid('', true), // password
91 'email_'.uniqid('', true).'@wallabag.it', // email
92 ]);
82 $tester->execute([ 93 $tester->execute([
83 'command' => $command->getName(), 94 'command' => $command->getName(),
84 ]); 95 ]);
@@ -87,6 +98,7 @@ class InstallCommandTest extends WallabagCoreTestCase
87 $this->assertContains('Setting up database.', $tester->getDisplay()); 98 $this->assertContains('Setting up database.', $tester->getDisplay());
88 $this->assertContains('Administration setup.', $tester->getDisplay()); 99 $this->assertContains('Administration setup.', $tester->getDisplay());
89 $this->assertContains('Config setup.', $tester->getDisplay()); 100 $this->assertContains('Config setup.', $tester->getDisplay());
101 $this->assertContains('Run migrations.', $tester->getDisplay());
90 } 102 }
91 103
92 public function testRunInstallCommandWithReset() 104 public function testRunInstallCommandWithReset()
@@ -96,18 +108,13 @@ class InstallCommandTest extends WallabagCoreTestCase
96 108
97 $command = $application->find('wallabag:install'); 109 $command = $application->find('wallabag:install');
98 110
99 // We mock the QuestionHelper
100 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
101 ->disableOriginalConstructor()
102 ->getMock();
103 $question->expects($this->any())
104 ->method('ask')
105 ->will($this->returnValue('yes_'.uniqid('', true)));
106
107 // We override the standard helper with our mock
108 $command->getHelperSet()->set($question, 'question');
109
110 $tester = new CommandTester($command); 111 $tester = new CommandTester($command);
112 $tester->setInputs([
113 'y', // create super admin
114 'username_'.uniqid('', true), // username
115 'password_'.uniqid('', true), // password
116 'email_'.uniqid('', true).'@wallabag.it', // email
117 ]);
111 $tester->execute([ 118 $tester->execute([
112 'command' => $command->getName(), 119 'command' => $command->getName(),
113 '--reset' => true, 120 '--reset' => true,
@@ -115,19 +122,20 @@ class InstallCommandTest extends WallabagCoreTestCase
115 122
116 $this->assertContains('Checking system requirements.', $tester->getDisplay()); 123 $this->assertContains('Checking system requirements.', $tester->getDisplay());
117 $this->assertContains('Setting up database.', $tester->getDisplay()); 124 $this->assertContains('Setting up database.', $tester->getDisplay());
118 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 125 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
119 $this->assertContains('Administration setup.', $tester->getDisplay()); 126 $this->assertContains('Administration setup.', $tester->getDisplay());
120 $this->assertContains('Config setup.', $tester->getDisplay()); 127 $this->assertContains('Config setup.', $tester->getDisplay());
128 $this->assertContains('Run migrations.', $tester->getDisplay());
121 129
122 // we force to reset everything 130 // we force to reset everything
123 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 131 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
124 } 132 }
125 133
126 public function testRunInstallCommandWithDatabaseRemoved() 134 public function testRunInstallCommandWithDatabaseRemoved()
127 { 135 {
128 // skipped SQLite check when database is removed because while testing for the connection, 136 // skipped SQLite check when database is removed because while testing for the connection,
129 // the driver will create the file (so the database) before testing if database exist 137 // the driver will create the file (so the database) before testing if database exist
130 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { 138 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
131 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); 139 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.');
132 } 140 }
133 141
@@ -148,18 +156,13 @@ class InstallCommandTest extends WallabagCoreTestCase
148 156
149 $command = $application->find('wallabag:install'); 157 $command = $application->find('wallabag:install');
150 158
151 // We mock the QuestionHelper
152 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
153 ->disableOriginalConstructor()
154 ->getMock();
155 $question->expects($this->any())
156 ->method('ask')
157 ->will($this->returnValue('yes_'.uniqid('', true)));
158
159 // We override the standard helper with our mock
160 $command->getHelperSet()->set($question, 'question');
161
162 $tester = new CommandTester($command); 159 $tester = new CommandTester($command);
160 $tester->setInputs([
161 'y', // create super admin
162 'username_'.uniqid('', true), // username
163 'password_'.uniqid('', true), // password
164 'email_'.uniqid('', true).'@wallabag.it', // email
165 ]);
163 $tester->execute([ 166 $tester->execute([
164 'command' => $command->getName(), 167 'command' => $command->getName(),
165 ]); 168 ]);
@@ -168,6 +171,7 @@ class InstallCommandTest extends WallabagCoreTestCase
168 $this->assertContains('Setting up database.', $tester->getDisplay()); 171 $this->assertContains('Setting up database.', $tester->getDisplay());
169 $this->assertContains('Administration setup.', $tester->getDisplay()); 172 $this->assertContains('Administration setup.', $tester->getDisplay());
170 $this->assertContains('Config setup.', $tester->getDisplay()); 173 $this->assertContains('Config setup.', $tester->getDisplay());
174 $this->assertContains('Run migrations.', $tester->getDisplay());
171 175
172 // the current database doesn't already exist 176 // the current database doesn't already exist
173 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); 177 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
@@ -180,23 +184,12 @@ class InstallCommandTest extends WallabagCoreTestCase
180 184
181 $command = $application->find('wallabag:install'); 185 $command = $application->find('wallabag:install');
182 186
183 // We mock the QuestionHelper
184 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
185 ->disableOriginalConstructor()
186 ->getMock();
187
188 $question->expects($this->exactly(3))
189 ->method('ask')
190 ->will($this->onConsecutiveCalls(
191 false, // don't want to reset the entire database
192 true, // do want to reset the schema
193 false // don't want to create a new user
194 ));
195
196 // We override the standard helper with our mock
197 $command->getHelperSet()->set($question, 'question');
198
199 $tester = new CommandTester($command); 187 $tester = new CommandTester($command);
188 $tester->setInputs([
189 'n', // don't want to reset the entire database
190 'y', // do want to reset the schema
191 'n', // don't want to create a new user
192 ]);
200 $tester->execute([ 193 $tester->execute([
201 'command' => $command->getName(), 194 'command' => $command->getName(),
202 ]); 195 ]);
@@ -205,8 +198,9 @@ class InstallCommandTest extends WallabagCoreTestCase
205 $this->assertContains('Setting up database.', $tester->getDisplay()); 198 $this->assertContains('Setting up database.', $tester->getDisplay());
206 $this->assertContains('Administration setup.', $tester->getDisplay()); 199 $this->assertContains('Administration setup.', $tester->getDisplay());
207 $this->assertContains('Config setup.', $tester->getDisplay()); 200 $this->assertContains('Config setup.', $tester->getDisplay());
201 $this->assertContains('Run migrations.', $tester->getDisplay());
208 202
209 $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); 203 $this->assertContains('Dropping schema and creating schema', $tester->getDisplay());
210 } 204 }
211 205
212 public function testRunInstallCommandChooseNothing() 206 public function testRunInstallCommandChooseNothing()
@@ -235,22 +229,11 @@ class InstallCommandTest extends WallabagCoreTestCase
235 229
236 $command = $application->find('wallabag:install'); 230 $command = $application->find('wallabag:install');
237 231
238 // We mock the QuestionHelper
239 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
240 ->disableOriginalConstructor()
241 ->getMock();
242
243 $question->expects($this->exactly(2))
244 ->method('ask')
245 ->will($this->onConsecutiveCalls(
246 false, // don't want to reset the entire database
247 false // don't want to create a new user
248 ));
249
250 // We override the standard helper with our mock
251 $command->getHelperSet()->set($question, 'question');
252
253 $tester = new CommandTester($command); 232 $tester = new CommandTester($command);
233 $tester->setInputs([
234 'n', // don't want to reset the entire database
235 'n', // don't want to create a new user
236 ]);
254 $tester->execute([ 237 $tester->execute([
255 'command' => $command->getName(), 238 'command' => $command->getName(),
256 ]); 239 ]);
@@ -259,6 +242,7 @@ class InstallCommandTest extends WallabagCoreTestCase
259 $this->assertContains('Setting up database.', $tester->getDisplay()); 242 $this->assertContains('Setting up database.', $tester->getDisplay());
260 $this->assertContains('Administration setup.', $tester->getDisplay()); 243 $this->assertContains('Administration setup.', $tester->getDisplay());
261 $this->assertContains('Config setup.', $tester->getDisplay()); 244 $this->assertContains('Config setup.', $tester->getDisplay());
245 $this->assertContains('Run migrations.', $tester->getDisplay());
262 246
263 $this->assertContains('Creating schema', $tester->getDisplay()); 247 $this->assertContains('Creating schema', $tester->getDisplay());
264 } 248 }
@@ -270,26 +254,17 @@ class InstallCommandTest extends WallabagCoreTestCase
270 254
271 $command = $application->find('wallabag:install'); 255 $command = $application->find('wallabag:install');
272 256
273 // We mock the QuestionHelper
274 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
275 ->disableOriginalConstructor()
276 ->getMock();
277 $question->expects($this->any())
278 ->method('ask')
279 ->will($this->returnValue('yes_'.uniqid('', true)));
280
281 // We override the standard helper with our mock
282 $command->getHelperSet()->set($question, 'question');
283
284 $tester = new CommandTester($command); 257 $tester = new CommandTester($command);
285 $tester->execute([ 258 $tester->execute([
286 'command' => $command->getName(), 259 'command' => $command->getName(),
287 '--no-interaction' => true, 260 ], [
261 'interactive' => false,
288 ]); 262 ]);
289 263
290 $this->assertContains('Checking system requirements.', $tester->getDisplay()); 264 $this->assertContains('Checking system requirements.', $tester->getDisplay());
291 $this->assertContains('Setting up database.', $tester->getDisplay()); 265 $this->assertContains('Setting up database.', $tester->getDisplay());
292 $this->assertContains('Administration setup.', $tester->getDisplay()); 266 $this->assertContains('Administration setup.', $tester->getDisplay());
293 $this->assertContains('Config setup.', $tester->getDisplay()); 267 $this->assertContains('Config setup.', $tester->getDisplay());
268 $this->assertContains('Run migrations.', $tester->getDisplay());
294 } 269 }
295} 270}