Skip to content

Commit

Permalink
path to Array function
Browse files Browse the repository at this point in the history
  • Loading branch information
starker-xp committed Mar 5, 2018
1 parent bcbace8 commit 674b347
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Structure/MysqlDatabaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public function toArray()
$export['columns'] = [];
$columns = $this->getColumns();
foreach ($columns as $column) {
$export['columns'][$column->getName()] = $column->toArray();
$arrayColumn = $column->toArray();
unset($arrayColumn['table']);
$export['columns'][$column->getName()] = $arrayColumn;
}

$export['indexes'] = [];
Expand All @@ -125,6 +127,7 @@ public function toArray()
unset($arrayIndex['table'], $arrayIndex['unique']);
$export['indexes'][] = $arrayIndex;
}
$export = array_filter($export);

return [$this->getTable() => $export];
}
Expand Down
28 changes: 27 additions & 1 deletion tests/Structure/MysqlDatabaseTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,38 @@ public function testToArray()
],
'primary' => ['id'],
'uniques' => [
['name' => 'UNI_b80bb7740288fda1f201890375a60c8f', 'columns' => ['id'], ],
['name' => 'UNI_b80bb7740288fda1f201890375a60c8f', 'columns' => ['id'],],
],
],
];

$this->assertEquals($expected, $statements);
}

public function testToArrayWithoutIndexes()
{
$table = new MysqlDatabaseTable('login');
$table->addColumn(new MysqlDatabaseColumn('id', 'INT', '255', false, null, 'auto_increment'));
$table->addPrimary(['id']);
$statements = $table->toArray();

$expected = [
'login' => [
'columns' => [
'id' => [
'type' => 'INT',
'length' => '255',
'extra' => 'AUTO_INCREMENT',
'name' => 'id',
'nullable' => false,
'defaultValue' => null,
'collate' => null,
],
],
'primary' => ['id'],
],
];
$this->assertEquals($expected, $statements);
}

}

0 comments on commit 674b347

Please sign in to comment.