3 namespace Doctrine\Tests\DBAL\Schema\Platforms;
5 require_once __DIR__ . '/../../../TestInit.php';
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Types\Type;
12 class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
20 * @var \Doctrine\DBAL\Platforms\AbstractPlatform
24 public function setUp()
26 $this->comparator = new \Doctrine\DBAL\Schema\Comparator;
27 $this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
30 public function testSwitchPrimaryKeyOrder()
32 $tableOld = new Table("test");
33 $tableOld->addColumn('foo_id', 'integer');
34 $tableOld->addColumn('bar_id', 'integer');
35 $tableNew = clone $tableOld;
37 $tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
38 $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
40 $diff = $this->comparator->diffTable($tableOld, $tableNew);
41 $sql = $this->platform->getAlterTableSQL($diff);
45 'ALTER TABLE test DROP PRIMARY KEY',
46 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
54 public function testGenerateForeignKeySQL()
56 $tableOld = new Table("test");
57 $tableOld->addColumn('foo_id', 'integer');
58 $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
61 foreach ($tableOld->getForeignKeys() AS $fk) {
62 $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
65 $this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls);
71 public function testClobNoAlterTable()
73 $tableOld = new Table("test");
74 $tableOld->addColumn('id', 'integer');
75 $tableOld->addColumn('description', 'string', array('length' => 65536));
76 $tableNew = clone $tableOld;
78 $tableNew->setPrimaryKey(array('id'));
80 $diff = $this->comparator->diffTable($tableOld, $tableNew);
81 $sql = $this->platform->getAlterTableSQL($diff);
84 array('ALTER TABLE test ADD PRIMARY KEY (id)'),