RemoveNamespacedAssetsTest.php 2.33 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\Tests\DBAL\Schema\Visitor;

jeroendedauw's avatar
jeroendedauw committed
5
use Doctrine\DBAL\Platforms\MySqlPlatform;
6 7 8
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets;
9
use function array_keys;
10

Luís Cobucci's avatar
Luís Cobucci committed
11
class RemoveNamespacedAssetsTest extends \PHPUnit\Framework\TestCase
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
{
    /**
     * @group DBAL-204
     */
    public function testRemoveNamespacedAssets()
    {
        $config = new SchemaConfig;
        $config->setName("test");
        $schema = new Schema(array(), array(), $config);

        $schema->createTable("test.test");
        $schema->createTable("foo.bar");
        $schema->createTable("baz");

        $schema->visit(new RemoveNamespacedAssets());

        $tables = $schema->getTables();
29
        self::assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace.");
30
    }
31 32 33 34 35 36 37 38 39 40

    /**
     * @group DBAL-204
     */
    public function testCleanupForeignKeys()
    {
        $config = new SchemaConfig;
        $config->setName("test");
        $schema = new Schema(array(), array(), $config);

41 42 43 44 45 46 47 48 49 50 51
        $fooTable = $schema->createTable("foo.bar");
        $fooTable->addColumn('id', 'integer');

        $testTable = $schema->createTable("test.test");
        $testTable->addColumn('id', 'integer');

        $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));

        $schema->visit(new RemoveNamespacedAssets());

        $sql = $schema->toSql(new MySqlPlatform());
Gabriel Caruso's avatar
Gabriel Caruso committed
52
        self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
53 54 55 56 57 58 59 60 61 62 63
    }

    /**
     * @group DBAL-204
     */
    public function testCleanupForeignKeysDifferentOrder()
    {
        $config = new SchemaConfig;
        $config->setName("test");
        $schema = new Schema(array(), array(), $config);

64 65 66 67 68 69 70 71 72 73 74
        $testTable = $schema->createTable("test.test");
        $testTable->addColumn('id', 'integer');

        $fooTable = $schema->createTable("foo.bar");
        $fooTable->addColumn('id', 'integer');

        $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));

        $schema->visit(new RemoveNamespacedAssets());

        $sql = $schema->toSql(new MySqlPlatform());
Gabriel Caruso's avatar
Gabriel Caruso committed
75
        self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
76
    }
77
}