aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
diff options
context:
space:
mode:
authoradev <adev2000@gmail.com>2017-05-15 20:47:59 +0200
committeradev <adev2000@gmail.com>2017-05-31 16:03:54 +0200
commit7ab5eb9508921d84b4b4ec84a59135d536da748e (patch)
tree725d9fae04d07a2c0aec2d2f5a19e1b43ec7a5d1 /tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
parent4423b88c5b2c2d530b0a83a822f521a61ca4d4b8 (diff)
downloadwallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.tar.gz
wallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.tar.zst
wallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.zip
Isolated tests
Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation.
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command/InstallCommandTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php67
1 files changed, 41 insertions, 26 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 71c2ffc6..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()
@@ -120,7 +135,7 @@ class InstallCommandTest extends WallabagCoreTestCase
120 { 135 {
121 // 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,
122 // 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
123 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) {
124 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); 139 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.');
125 } 140 }
126 141