Skip to content

Commit

Permalink
Fixed Dumper - table with no primary keys (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
lulco authored Dec 20, 2021
1 parent 3e6a142 commit 597cd8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### [Unreleased][unreleased]

#### Fixed
- Dumper - table with no primary keys

### [1.11.1] - 2021-12-07
#### Fixed
- Removed phpspec/prophecy from misused replace in `composer.json`
Expand Down
2 changes: 2 additions & 0 deletions src/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function dumpTables(array $tables, string $dumpType): string
$primaryColumns = $table->getPrimaryColumnNames();
if ($primaryColumns) {
$tableMigration .= ", " . $this->columnsToString($primaryColumns);
} elseif ($table->getAction() === MigrationTable::ACTION_CREATE) {
$tableMigration .= ", false";
}
$tableMigration .= ")\n";
if ($table->getAutoIncrement() && $table->getAutoIncrement() !== 1 && $this->autoIncrement) {
Expand Down
12 changes: 6 additions & 6 deletions tests/Dumper/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function testIndent()
$tables = [$migrationTable];

$dumper = new Dumper(' ');
$output = "\$this->table('table_1')\n ->addColumn('id', 'integer')\n ->create();";
$output = "\$this->table('table_1', false)\n ->addColumn('id', 'integer')\n ->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));

$dumper = new Dumper("\t");
$output = "\$this->table('table_1')\n\t->addColumn('id', 'integer')\n\t->create();";
$output = "\$this->table('table_1', false)\n\t->addColumn('id', 'integer')\n\t->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));

$dumper = new Dumper('custom_indent');
$output = "\$this->table('table_1')\ncustom_indent->addColumn('id', 'integer')\ncustom_indent->create();";
$output = "\$this->table('table_1', false)\ncustom_indent->addColumn('id', 'integer')\ncustom_indent->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));
}

Expand All @@ -39,15 +39,15 @@ public function testBaseIndent()
$tables = [$migrationTable];

$dumper = new Dumper(' ', 2);
$output = " \$this->table('table_1')\n ->addColumn('id', 'integer')\n ->create();";
$output = " \$this->table('table_1', false)\n ->addColumn('id', 'integer')\n ->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));

$dumper = new Dumper("\t", 2);
$output = "\t\t\$this->table('table_1')\n\t\t\t->addColumn('id', 'integer')\n\t\t\t->create();";
$output = "\t\t\$this->table('table_1', false)\n\t\t\t->addColumn('id', 'integer')\n\t\t\t->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));

$dumper = new Dumper('custom_indent', 2);
$output = "custom_indentcustom_indent\$this->table('table_1')\ncustom_indentcustom_indentcustom_indent->addColumn('id', 'integer')\ncustom_indentcustom_indentcustom_indent->create();";
$output = "custom_indentcustom_indent\$this->table('table_1', false)\ncustom_indentcustom_indentcustom_indent->addColumn('id', 'integer')\ncustom_indentcustom_indentcustom_indent->create();";
$this->assertEquals($output, $dumper->dumpTables($tables, 'up'));
}

Expand Down

0 comments on commit 597cd8f

Please sign in to comment.