Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / Visitor / RemoveNamespacedAssetsTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema\Visitor;
4
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;
9
10 class RemoveNamespacedAssetsTest extends \PHPUnit_Framework_TestCase
11 {
12     /**
13      * @group DBAL-204
14      */
15     public function testRemoveNamespacedAssets()
16     {
17         $config = new SchemaConfig;
18         $config->setName("test");
19         $schema = new Schema(array(), array(), $config);
20
21         $schema->createTable("test.test");
22         $schema->createTable("foo.bar");
23         $schema->createTable("baz");
24
25         $schema->visit(new RemoveNamespacedAssets());
26
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.");
29     }
30
31     /**
32      * @group DBAL-204
33      */
34     public function testCleanupForeignKeys()
35     {
36         $config = new SchemaConfig;
37         $config->setName("test");
38         $schema = new Schema(array(), array(), $config);
39
40         $fooTable = $schema->createTable("foo.bar");
41         $fooTable->addColumn('id', 'integer');
42
43         $testTable = $schema->createTable("test.test");
44         $testTable->addColumn('id', 'integer');
45
46         $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
47
48         $schema->visit(new RemoveNamespacedAssets());
49
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");
52     }
53
54     /**
55      * @group DBAL-204
56      */
57     public function testCleanupForeignKeysDifferentOrder()
58     {
59         $config = new SchemaConfig;
60         $config->setName("test");
61         $schema = new Schema(array(), array(), $config);
62
63         $testTable = $schema->createTable("test.test");
64         $testTable->addColumn('id', 'integer');
65
66         $fooTable = $schema->createTable("foo.bar");
67         $fooTable->addColumn('id', 'integer');
68
69         $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
70
71         $schema->visit(new RemoveNamespacedAssets());
72
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");
75     }
76 }
77