3 namespace Doctrine\Tests\DBAL\Schema;
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;
13 class MySqlSchemaManagerTest extends \PHPUnit_Framework_TestCase
17 * @var \Doctrine\DBAL\Schema\AbstractSchemaManager
21 public function setUp()
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',
29 array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)
31 $this->manager = new MySqlSchemaManager($this->conn);
34 public function testCompositeForeignKeys()
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.");
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()));
45 public function getFKDefinition()
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",
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",
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",