Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / MySqlSchemaManagerTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema;
4
5 use Doctrine\Common\EventManager;
6 use Doctrine\DBAL\Connection;
7 use Doctrine\DBAL\Configuration;
8 use Doctrine\DBAL\Events;
9 use Doctrine\DBAL\Schema\MySqlSchemaManager;
10 use Doctrine\Tests\DBAL\Mocks;
11 use Doctrine\Tests\TestUtil;
12
13 class MySqlSchemaManagerTest extends \PHPUnit_Framework_TestCase
14 {
15     /**
16      *
17      * @var \Doctrine\DBAL\Schema\AbstractSchemaManager
18      */
19     private $manager;
20
21     public function setUp()
22     {
23         $eventManager = new EventManager();
24         $driverMock = $this->getMock('Doctrine\DBAL\Driver');
25         $platform = $this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform');
26         $this->conn = $this->getMock(
27             'Doctrine\DBAL\Connection',
28             array('fetchAll'),
29             array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)
30         );
31         $this->manager = new MySqlSchemaManager($this->conn);
32     }
33
34     public function testCompositeForeignKeys()
35     {
36         $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition()));
37         $fkeys = $this->manager->listTableForeignKeys('dummy');
38         $this->assertEquals(1, count($fkeys), "Table has to have one foreign key.");
39
40         $this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
41         $this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
42         $this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
43     }
44
45     public function getFKDefinition()
46     {
47         return array(
48             array(
49                 "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
50                 "COLUMN_NAME" => "column_1",
51                 "REFERENCED_TABLE_NAME" => "dummy",
52                 "REFERENCED_COLUMN_NAME" => "column_1",
53                 "update_rule" => "RESTRICT",
54                 "delete_rule" => "RESTRICT",
55             ),
56             array(
57                 "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
58                 "COLUMN_NAME" => "column_2",
59                 "REFERENCED_TABLE_NAME" => "dummy",
60                 "REFERENCED_COLUMN_NAME" => "column_2",
61                 "update_rule" => "RESTRICT",
62                 "delete_rule" => "RESTRICT",
63             ),
64             array(
65                 "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
66                 "COLUMN_NAME" => "column_3",
67                 "REFERENCED_TABLE_NAME" => "dummy",
68                 "REFERENCED_COLUMN_NAME" => "column_3",
69                 "update_rule" => "RESTRICT",
70                 "delete_rule" => "RESTRICT",
71             )
72         );
73     }
74 }