Skip to content

Commit

Permalink
Add tests for index reflection
Browse files Browse the repository at this point in the history
Fix issues with primary key reflection and add missing tests for
reflection of KEY statements.
  • Loading branch information
markstory committed Jun 2, 2013
1 parent f31d30b commit 13f7da9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Database/Schema/MysqlSchema.php
Expand Up @@ -183,7 +183,7 @@ public function convertIndexDescription(Table $table, $row) {
$type = strtolower($row['Index_type']);
} elseif ($row['Non_unique'] == 0 && $type !== 'primary') {
$type = 'unique';
} else {
} elseif ($type !== 'primary') {
$type = 'index';
}

Expand All @@ -203,7 +203,7 @@ public function convertIndexDescription(Table $table, $row) {
// MySQL multi column indexes come back
// as multiple rows.
if (!empty($existing)) {
$columns = array_merge($existing['columns'], $columns);
$columns = array_unique(array_merge($existing['columns'], $columns));
$length = array_merge($existing['length'], $length);
}
if ($isIndex) {
Expand Down
19 changes: 12 additions & 7 deletions lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -282,6 +282,8 @@ public function testDescribeTableIndexes() {
$schema = new SchemaCollection($connection);
$result = $schema->describe('articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);

$this->assertCount(2, $result->constraints());
$expected = [
'primary' => [
'type' => 'primary',
Expand All @@ -296,13 +298,16 @@ public function testDescribeTableIndexes() {
]
]
];
foreach ($expected as $name => $props) {
$this->assertEquals(
$props,
$result->constraint($name),
'Index definition does not match for ' . $name
);
}
$this->assertEquals($expected['primary'], $result->constraint('primary'));
$this->assertEquals($expected['length_idx'], $result->constraint('length_idx'));

$this->assertCount(1, $result->indexes());
$expected = [
'type' => 'index',
'columns' => ['author_id'],
'length' => []
];
$this->assertEquals($expected, $result->index('author_idx'));
}

/**
Expand Down

0 comments on commit 13f7da9

Please sign in to comment.