Skip to content

Commit 2d269fd

Browse files
fix(stub): migration test now consider multiword container name and generates correct table name
1 parent 6d4d884 commit 2d269fd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Generator/Commands/TestUnitTestGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class TestUnitTestGenerator extends GeneratorCommand implements ComponentsGenera
1919
['model', null, InputOption::VALUE_OPTIONAL, 'The model this tests is for.'],
2020
['stub', null, InputOption::VALUE_OPTIONAL, 'The stub file to load for this generator.'],
2121
['event', null, InputOption::VALUE_OPTIONAL, 'The Event to generate tests for'],
22+
['tablename', null, InputOption::VALUE_OPTIONAL, 'The DB Table to generate tests for'],
2223
];
2324
/**
2425
* The console command name.
@@ -54,6 +55,7 @@ public function getUserInputs(): ?array
5455
$model = $this->option('model');
5556
$stub = $this->option('stub');
5657
$event = $this->option('event');
58+
$tablename = $this->option('tablename');
5759

5860
if ($stub) {
5961
if ($event) {
@@ -90,6 +92,7 @@ public function getUserInputs(): ?array
9092
'models' => $models,
9193
'_models' => Str::lower($models),
9294
'event' => $event,
95+
'table-name' => $tablename,
9396
],
9497
'file-parameters' => [
9598
'file-name' => $this->fileName,

Generator/Stubs/tests/unit/migration.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Schema;
1313
*/
1414
class {{class-name}} extends TestCase
1515
{
16-
public function test_{{_models}}_table_has_expected_columns(): void
16+
public function test_{{table-name}}_table_has_expected_columns(): void
1717
{
1818
$columns = [
1919
'id',
@@ -23,7 +23,7 @@ class {{class-name}} extends TestCase
2323
];
2424

2525
foreach ($columns as $column) {
26-
$this->assertTrue(Schema::hasColumn('{{_models}}', $column));
26+
$this->assertTrue(Schema::hasColumn('{{table-name}}', $column));
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)