Skip to content

Commit

Permalink
Add migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
norbybaru committed Jul 7, 2024
1 parent 35605cb commit 811fb60
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Console/Commands/ModuleMakeMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle()

if ($create) {
$arguments['--create'] = $this->getPluralName($create);
} else {
} elseif ($update) {
$arguments['--table'] = $this->getPluralName($update);
}

Expand Down
52 changes: 52 additions & 0 deletions tests/Commands/MakeMigrationCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace NorbyBaru\Modularize\Tests\Commands;

use NorbyBaru\Modularize\Tests\MakeCommandTestCase;

class MakeMigrationCommandTest extends MakeCommandTestCase
{
public function test_it_should_create_migration_file()
{
$this->artisan(
command: 'module:make:migration',
parameters: [
'name' => 'create_posts_table',
'--module' => $this->moduleName,
]
)
->assertSuccessful();

$this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'create_posts_table.php');
}

public function test_it_should_create_migration_file_with_create_option()
{
$this->artisan(
command: 'module:make:migration',
parameters: [
'name' => 'create_posts_table',
'--module' => $this->moduleName,
'--create' => 'posts',
]
)
->assertSuccessful();

$this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'create_posts_table.php');
}

public function test_it_should_create_migration_file_with_table_option()
{
$this->artisan(
command: 'module:make:migration',
parameters: [
'name' => 'add_title_to_posts_table',
'--module' => $this->moduleName,
'--table' => 'posts',
]
)
->assertSuccessful();

$this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'add_title_to_posts_table.php');
}
}
3 changes: 1 addition & 2 deletions tests/MakeCommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public function cleanUp(): void

protected function assertMigrationFile(string $module, string $migrationFilename): void
{
$migrations = $this->files->allFiles(directory: $this->getModulePath($module));
dd($migrations);
$migrations = $this->files->allFiles(directory: $this->getModulePath($module).'/Database/migrations');
$this->assertNotEmpty(actual: $migrations);
$this->assertEquals(
expected: 1,
Expand Down

0 comments on commit 811fb60

Please sign in to comment.