MySqlSchemaManagerTest.php 2.7KB

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