MySqlSchemaManagerTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Doctrine\Tests\DBAL\Functional\Schema;
  3. use Doctrine\DBAL\Schema\Table;
  4. use Doctrine\DBAL\Schema\Schema;
  5. require_once __DIR__ . '/../../../TestInit.php';
  6. class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
  7. {
  8. public function testSwitchPrimaryKeyColumns()
  9. {
  10. $tableOld = new Table("switch_primary_key_columns");
  11. $tableOld->addColumn('foo_id', 'integer');
  12. $tableOld->addColumn('bar_id', 'integer');
  13. $tableNew = clone $tableOld;
  14. $this->_sm->createTable($tableOld);
  15. $tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
  16. $tableNew = clone $tableFetched;
  17. $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
  18. $comparator = new \Doctrine\DBAL\Schema\Comparator;
  19. $this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
  20. }
  21. public function testDiffTableBug()
  22. {
  23. $schema = new Schema();
  24. $table = $schema->createTable('diffbug_routing_translations');
  25. $table->addColumn('id', 'integer');
  26. $table->addColumn('route', 'string');
  27. $table->addColumn('locale', 'string');
  28. $table->addColumn('attribute', 'string');
  29. $table->addColumn('localized_value', 'string');
  30. $table->addColumn('original_value', 'string');
  31. $table->setPrimaryKey(array('id'));
  32. $table->addUniqueIndex(array('route', 'locale', 'attribute'));
  33. $table->addIndex(array('localized_value')); // this is much more selective than the unique index
  34. $this->_sm->createTable($table);
  35. $tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations");
  36. $comparator = new \Doctrine\DBAL\Schema\Comparator;
  37. $diff = $comparator->diffTable($tableFetched, $table);
  38. $this->assertFalse($diff, "no changes expected.");
  39. }
  40. }