3 namespace Doctrine\Tests\DBAL\Schema\Visitor;
5 use Doctrine\DBAL\Schema\Schema;
6 use Doctrine\DBAL\Schema\SchemaConfig;
7 use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets;
8 use Doctrine\DBAL\Platforms\MySqlPlatform;
10 class RemoveNamespacedAssetsTest extends \PHPUnit_Framework_TestCase
15 public function testRemoveNamespacedAssets()
17 $config = new SchemaConfig;
18 $config->setName("test");
19 $schema = new Schema(array(), array(), $config);
21 $schema->createTable("test.test");
22 $schema->createTable("foo.bar");
23 $schema->createTable("baz");
25 $schema->visit(new RemoveNamespacedAssets());
27 $tables = $schema->getTables();
28 $this->assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace.");
34 public function testCleanupForeignKeys()
36 $config = new SchemaConfig;
37 $config->setName("test");
38 $schema = new Schema(array(), array(), $config);
40 $fooTable = $schema->createTable("foo.bar");
41 $fooTable->addColumn('id', 'integer');
43 $testTable = $schema->createTable("test.test");
44 $testTable->addColumn('id', 'integer');
46 $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
48 $schema->visit(new RemoveNamespacedAssets());
50 $sql = $schema->toSql(new MySqlPlatform());
51 $this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
57 public function testCleanupForeignKeysDifferentOrder()
59 $config = new SchemaConfig;
60 $config->setName("test");
61 $schema = new Schema(array(), array(), $config);
63 $testTable = $schema->createTable("test.test");
64 $testTable->addColumn('id', 'integer');
66 $fooTable = $schema->createTable("foo.bar");
67 $fooTable->addColumn('id', 'integer');
69 $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
71 $schema->visit(new RemoveNamespacedAssets());
73 $sql = $schema->toSql(new MySqlPlatform());
74 $this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");