/
MySqlSchemaManagerTest.php
67 lines (53 loc) · 2.38 KB
/
MySqlSchemaManagerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testSwitchPrimaryKeyColumns()
{
$tableOld = new Table("switch_primary_key_columns");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;
$this->_sm->createTable($tableOld);
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
$tableNew = clone $tableFetched;
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
$comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
}
public function testDiffTableBug()
{
$schema = new Schema();
$table = $schema->createTable('diffbug_routing_translations');
$table->addColumn('id', 'integer');
$table->addColumn('route', 'string');
$table->addColumn('locale', 'string');
$table->addColumn('attribute', 'string');
$table->addColumn('localized_value', 'string');
$table->addColumn('original_value', 'string');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('route', 'locale', 'attribute'));
$table->addIndex(array('localized_value')); // this is much more selective than the unique index
$this->_sm->createTable($table);
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations");
$comparator = new \Doctrine\DBAL\Schema\Comparator;
$diff = $comparator->diffTable($tableFetched, $table);
$this->assertFalse($diff, "no changes expected.");
}
public function testFulltextIndex()
{
$table = new Table('fulltext_index');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'f_index');
$table->addOption('engine', 'MyISAM');
$index = $table->getIndex('f_index');
$index->addFlag('fulltext');
$this->_sm->dropAndCreateTable($table);
$indexes = $this->_sm->listTableIndexes('fulltext_index');
$this->assertArrayHasKey('f_index', $indexes);
$this->assertTrue($indexes['f_index']->hasFlag('fulltext'));
}
}