SchemaSqlCollectorTest.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Doctrine\Tests\DBAL\Schema\Visitor;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Schema\Table;
  6. use Doctrine\DBAL\Types\Type;
  7. class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function testCreateSchema()
  10. {
  11. $platformMock = $this->getMock(
  12. 'Doctrine\DBAL\Platforms\MySqlPlatform',
  13. array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')
  14. );
  15. $platformMock->expects($this->exactly(2))
  16. ->method('getCreateTableSql')
  17. ->will($this->returnValue(array("foo")));
  18. $platformMock->expects($this->exactly(1))
  19. ->method('getCreateSequenceSql')
  20. ->will($this->returnValue(array("bar")));
  21. $platformMock->expects($this->exactly(1))
  22. ->method('getCreateForeignKeySql')
  23. ->will($this->returnValue(array("baz")));
  24. $schema = $this->createFixtureSchema();
  25. $sql = $schema->toSql($platformMock);
  26. $this->assertEquals(array("foo", "foo", "bar", "baz"), $sql);
  27. }
  28. public function testDropSchema()
  29. {
  30. $platformMock = $this->getMock(
  31. 'Doctrine\DBAL\Platforms\MySqlPlatform',
  32. array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')
  33. );
  34. $platformMock->expects($this->exactly(2))
  35. ->method('getDropTableSql')
  36. ->will($this->returnValue("tbl"));
  37. $platformMock->expects($this->exactly(1))
  38. ->method('getDropSequenceSql')
  39. ->will($this->returnValue("seq"));
  40. $platformMock->expects($this->exactly(1))
  41. ->method('getDropForeignKeySql')
  42. ->will($this->returnValue("fk"));
  43. $schema = $this->createFixtureSchema();
  44. $sql = $schema->toDropSql($platformMock);
  45. $this->assertEquals(array("fk", "seq", "tbl", "tbl"), $sql);
  46. }
  47. /**
  48. * @return Schema
  49. */
  50. public function createFixtureSchema()
  51. {
  52. $schema = new Schema();
  53. $tableA = $schema->createTable("foo");
  54. $tableA->addColumn("id", 'integer');
  55. $tableA->addColumn("bar", 'string', array('length' => 255));
  56. $tableA->setPrimaryKey(array("id"));
  57. $schema->createSequence("foo_seq");
  58. $tableB = $schema->createTable("bar");
  59. $tableB->addColumn("id", 'integer');
  60. $tableB->setPrimaryKey(array("id"));
  61. $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id"));
  62. return $schema;
  63. }
  64. }