MySqlSchemaManagerTest.php 2.7 KB

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