Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / Platforms / MySQLSchemaTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema\Platforms;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Types\Type;
11
12 class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
13 {
14     /**
15      * @var Comparator
16      */
17     private $comparator;
18     /**
19      *
20      * @var \Doctrine\DBAL\Platforms\AbstractPlatform
21      */
22     private $platform;
23
24     public function setUp()
25     {
26         $this->comparator = new \Doctrine\DBAL\Schema\Comparator;
27         $this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
28     }
29
30     public function testSwitchPrimaryKeyOrder()
31     {
32         $tableOld = new Table("test");
33         $tableOld->addColumn('foo_id', 'integer');
34         $tableOld->addColumn('bar_id', 'integer');
35         $tableNew = clone $tableOld;
36
37         $tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
38         $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
39
40         $diff = $this->comparator->diffTable($tableOld, $tableNew);
41         $sql = $this->platform->getAlterTableSQL($diff);
42
43         $this->assertEquals(
44             array(
45                 'ALTER TABLE test DROP PRIMARY KEY',
46                 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
47             ), $sql
48         );
49     }
50
51     /**
52      * @group DBAL-132
53      */
54     public function testGenerateForeignKeySQL()
55     {
56         $tableOld = new Table("test");
57         $tableOld->addColumn('foo_id', 'integer');
58         $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
59
60         $sqls = array();
61         foreach ($tableOld->getForeignKeys() AS $fk) {
62             $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
63         }
64
65         $this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls);
66     }
67
68     /**
69      * @group DDC-1737
70      */
71     public function testClobNoAlterTable()
72     {
73         $tableOld = new Table("test");
74         $tableOld->addColumn('id', 'integer');
75         $tableOld->addColumn('description', 'string', array('length' => 65536));
76         $tableNew = clone $tableOld;
77
78         $tableNew->setPrimaryKey(array('id'));
79
80         $diff = $this->comparator->diffTable($tableOld, $tableNew);
81         $sql = $this->platform->getAlterTableSQL($diff);
82
83         $this->assertEquals(
84             array('ALTER TABLE test ADD PRIMARY KEY (id)'),
85             $sql
86         );
87     }
88 }