diff --git a/src/Structure/MysqlDatabaseTable.php b/src/Structure/MysqlDatabaseTable.php index 75a35d1..94642c8 100644 --- a/src/Structure/MysqlDatabaseTable.php +++ b/src/Structure/MysqlDatabaseTable.php @@ -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'] = []; @@ -125,6 +127,7 @@ public function toArray() unset($arrayIndex['table'], $arrayIndex['unique']); $export['indexes'][] = $arrayIndex; } + $export = array_filter($export); return [$this->getTable() => $export]; } diff --git a/tests/Structure/MysqlDatabaseTableTest.php b/tests/Structure/MysqlDatabaseTableTest.php index c2d3106..ffe9514 100644 --- a/tests/Structure/MysqlDatabaseTableTest.php +++ b/tests/Structure/MysqlDatabaseTableTest.php @@ -201,7 +201,7 @@ public function testToArray() ], 'primary' => ['id'], 'uniques' => [ - ['name' => 'UNI_b80bb7740288fda1f201890375a60c8f', 'columns' => ['id'], ], + ['name' => 'UNI_b80bb7740288fda1f201890375a60c8f', 'columns' => ['id'],], ], ], ]; @@ -209,4 +209,30 @@ public function testToArray() $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); + } + }