From d393217244b059be8be98250c6f65d2044434996 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 18 Oct 2015 18:33:07 +0200 Subject: [PATCH] Testing All methods for addSql --- .../Tests/Functional/FunctionalTest.php | 21 ++++--- .../MigrateAddSqlPostAndPreUpAndDownTest.php | 60 +++++++++++++++++++ .../Functional/MigrateAddSqlPostUpTest.php | 31 ---------- 3 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostAndPreUpAndDownTest.php delete mode 100644 tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostUpTest.php diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Functional/FunctionalTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Functional/FunctionalTest.php index fcd37f15c1..a2cf866ac6 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/Functional/FunctionalTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/Functional/FunctionalTest.php @@ -180,8 +180,10 @@ public function testAddSql() public function testAddSqlInPostUp() { - $this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Stub\Functional\MigrateAddSqlPostUpTest'); - $tableName = \Doctrine\DBAL\Migrations\Tests\Stub\Functional\MigrateAddSqlPostUpTest::TABLE_NAME; + $this->config->registerMigration(1, 'Doctrine\DBAL\Migrations\Tests\Stub\Functional\MigrateAddSqlPostAndPreUpAndDownTest'); + $tableName = \Doctrine\DBAL\Migrations\Tests\Stub\Functional\MigrateAddSqlPostAndPreUpAndDownTest::TABLE_NAME; + + $this->config->getConnection()->executeQuery(sprintf("CREATE TABLE IF NOT EXISTS %s (test INT)", $tableName)); $migration = new \Doctrine\DBAL\Migrations\Migration($this->config); $migration->migrate(1); @@ -189,16 +191,19 @@ public function testAddSqlInPostUp() $migrations = $this->config->getMigrations(); $this->assertTrue($migrations[1]->isMigrated()); - $schema = $this->config->getConnection()->getSchemaManager()->createSchema(); - $this->assertTrue($schema->hasTable($tableName)); - $check = $this->config->getConnection()->fetchAll("select * from $tableName"); + $check = $this->config->getConnection()->fetchColumn("select SUM(test) as sum from $tableName"); + $this->assertNotEmpty($check); - $this->assertEquals('test', $check[0]['test']); + $this->assertEquals(6, $check); $migration->migrate(0); $this->assertFalse($migrations[1]->isMigrated()); - $schema = $this->config->getConnection()->getSchemaManager()->createSchema(); - $this->assertFalse($schema->hasTable($tableName)); + $check = $this->config->getConnection()->fetchColumn("select SUM(test) as sum from $tableName"); + $this->assertNotEmpty($check); + $this->assertEquals(21, $check); + + + $this->config->getConnection()->executeQuery(sprintf("DROP TABLE %s ", $tableName)); } public function testVersionInDatabaseWithoutRegisteredMigrationStillMigrates() diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostAndPreUpAndDownTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostAndPreUpAndDownTest.php new file mode 100644 index 0000000000..1aa756f81e --- /dev/null +++ b/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostAndPreUpAndDownTest.php @@ -0,0 +1,60 @@ +addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [1] + ); + } + + public function up(Schema $schema) + { + $this->addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [2] + ); + } + + public function postUp(Schema $schema) + { + $this->addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [3] + ); + } + + public function preDown(Schema $schema) + { + $this->addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [4] + ); + } + + public function down(Schema $schema) + { + $this->addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [5] + ); + } + + public function postDown(Schema $schema) + { + $this->addSql( + sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), + [6] + ); + } +} diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostUpTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostUpTest.php deleted file mode 100644 index 9a22d0e71d..0000000000 --- a/tests/Doctrine/DBAL/Migrations/Tests/Stub/Functional/MigrateAddSqlPostUpTest.php +++ /dev/null @@ -1,31 +0,0 @@ -createTable(self::TABLE_NAME); - $table->addColumn('test', Type::STRING, ['length' => 64]); - } - - public function postUp(Schema $schema) - { - $this->addSql( - sprintf("INSERT INTO %s (test) values (?)", self::TABLE_NAME), - ['test'] - ); - } - - public function down(Schema $schema) - { - $schema->dropTable(self::TABLE_NAME); - } -}