Browse Source

Clean up schema test cases by combining everything to one scenario

Yves P 10 years ago
parent
commit
02d1361821

+ 12 - 28
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -743,16 +743,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE `posts` ADD CONSTRAINT `author_fk` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;
-SQL;
-        $result = $table->addConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -761,12 +752,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE `posts` ADD CONSTRAINT `category_fk` FOREIGN KEY (`category_id`, `category_name`) REFERENCES `categories` (`id`, `name`) ON UPDATE CASCADE ON DELETE CASCADE;
-SQL;
+        $expected = [
+            'ALTER TABLE `posts` ADD CONSTRAINT `author_fk` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;',
+            'ALTER TABLE `posts` ADD CONSTRAINT `category_fk` FOREIGN KEY (`category_id`, `category_name`) REFERENCES `categories` (`id`, `name`) ON UPDATE CASCADE ON DELETE CASCADE;'
+        ];
         $result = $table->addConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**
@@ -800,16 +792,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE `posts` DROP FOREIGN KEY `author_fk`;
-SQL;
-        $result = $table->dropConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -818,12 +801,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE `posts` DROP FOREIGN KEY `category_fk`;
-SQL;
+        $expected = [
+            'ALTER TABLE `posts` DROP FOREIGN KEY `author_fk`;',
+            'ALTER TABLE `posts` DROP FOREIGN KEY `category_fk`;'
+        ];
         $result = $table->dropConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**

+ 12 - 28
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -826,16 +826,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE "posts" ADD CONSTRAINT "author_fk" FOREIGN KEY ("author_id") REFERENCES "authors" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE;
-SQL;
-        $result = $table->addConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -844,12 +835,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE "posts" ADD CONSTRAINT "category_fk" FOREIGN KEY ("category_id", "category_name") REFERENCES "categories" ("id", "name") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE;
-SQL;
+        $expected = [
+            'ALTER TABLE "posts" ADD CONSTRAINT "author_fk" FOREIGN KEY ("author_id") REFERENCES "authors" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE;',
+            'ALTER TABLE "posts" ADD CONSTRAINT "category_fk" FOREIGN KEY ("category_id", "category_name") REFERENCES "categories" ("id", "name") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE;'
+        ];
         $result = $table->addConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**
@@ -883,16 +875,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE "posts" DROP CONSTRAINT "author_fk";
-SQL;
-        $result = $table->dropConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -901,12 +884,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE "posts" DROP CONSTRAINT "category_fk";
-SQL;
+        $expected = [
+            'ALTER TABLE "posts" DROP CONSTRAINT "author_fk";',
+            'ALTER TABLE "posts" DROP CONSTRAINT "category_fk";'
+        ];
         $result = $table->dropConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**

+ 2 - 37
tests/TestCase/Database/Schema/SqliteSchemaTest.php

@@ -575,25 +575,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = [
-            'DROP TABLE IF EXISTS "tmp_posts"',
-            'ALTER TABLE "posts" RENAME TO "tmp_posts"',
-            'CREATE TABLE "posts" (
-"author_id" INTEGER NOT NULL,
-"category_id" INTEGER NOT NULL,
-"category_name" INTEGER NOT NULL,
-CONSTRAINT "author_fk" FOREIGN KEY ("author_id") REFERENCES "authors" ("id") ON UPDATE CASCADE ON DELETE CASCADE
-)',
-            'INSERT INTO "posts"(author_id, category_id, category_name) SELECT author_id, category_id, category_name FROM "tmp_posts"',
-            'DROP TABLE IF EXISTS "tmp_posts"'
-        ];
-        $result = $table->addConstraintSql($connection);
-        $this->assertCount(5, $result);
-        $this->assertTextEquals($expected, $result);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -651,24 +633,7 @@ CONSTRAINT "category_fk" FOREIGN KEY ("category_id", "category_name") REFERENCES
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = [
-            'DROP TABLE IF EXISTS "tmp_posts"',
-            'ALTER TABLE "posts" RENAME TO "tmp_posts"',
-            'CREATE TABLE "posts" (
-"author_id" INTEGER NOT NULL,
-"category_id" INTEGER NOT NULL,
-"category_name" INTEGER NOT NULL
-)',
-            'INSERT INTO "posts"(author_id, category_id, category_name) SELECT author_id, category_id, category_name FROM "tmp_posts"',
-            'DROP TABLE IF EXISTS "tmp_posts"'
-        ];
-        $result = $table->dropConstraintSql($connection);
-        $this->assertCount(5, $result);
-        $this->assertTextEquals($expected, $result);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],

+ 12 - 28
tests/TestCase/Database/Schema/SqlserverSchemaTest.php

@@ -685,16 +685,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE [posts] ADD CONSTRAINT [author_fk] FOREIGN KEY ([author_id]) REFERENCES [authors] ([id]) ON UPDATE CASCADE ON DELETE CASCADE;
-SQL;
-        $result = $table->addConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -703,12 +694,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE [posts] ADD CONSTRAINT [category_fk] FOREIGN KEY ([category_id], [category_name]) REFERENCES [categories] ([id], [name]) ON UPDATE CASCADE ON DELETE CASCADE;
-SQL;
+        $expected = [
+            'ALTER TABLE [posts] ADD CONSTRAINT [author_fk] FOREIGN KEY ([author_id]) REFERENCES [authors] ([id]) ON UPDATE CASCADE ON DELETE CASCADE;',
+            'ALTER TABLE [posts] ADD CONSTRAINT [category_fk] FOREIGN KEY ([category_id], [category_name]) REFERENCES [categories] ([id], [name]) ON UPDATE CASCADE ON DELETE CASCADE;'
+        ];
         $result = $table->addConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**
@@ -742,16 +734,7 @@ SQL;
                 'references' => ['authors', 'id'],
                 'update' => 'cascade',
                 'delete' => 'cascade'
-            ]);
-
-        $expected = <<<SQL
-ALTER TABLE [posts] DROP CONSTRAINT [author_fk];
-SQL;
-        $result = $table->dropConstraintSql($connection);
-        $this->assertCount(1, $result);
-        $this->assertTextEquals($expected, $result[0]);
-
-        $table
+            ])
             ->addConstraint('category_fk', [
                 'type' => 'foreign',
                 'columns' => ['category_id', 'category_name'],
@@ -760,12 +743,13 @@ SQL;
                 'delete' => 'cascade'
             ]);
 
-        $expected = <<<SQL
-ALTER TABLE [posts] DROP CONSTRAINT [category_fk];
-SQL;
+        $expected = [
+            'ALTER TABLE [posts] DROP CONSTRAINT [author_fk];',
+            'ALTER TABLE [posts] DROP CONSTRAINT [category_fk];'
+        ];
         $result = $table->dropConstraintSql($connection);
         $this->assertCount(2, $result);
-        $this->assertTextEquals($expected, $result[1]);
+        $this->assertEquals($expected, $result);
     }
 
     /**