Skip to content

Commit

Permalink
Merge pull request #225 from kitloong/feature/inject
Browse files Browse the repository at this point in the history
Move dependency injection to `handle`
  • Loading branch information
kitloong authored Aug 4, 2024
2 parents bb7d2ef + 9acdf19 commit 6dc429c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
34 changes: 21 additions & 13 deletions src/MigrateGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,33 @@ class MigrateGenerateCommand extends Command
protected bool $shouldLog = false;

protected int $nextBatchNumber = 0;

public function __construct(
protected MigrationRepositoryInterface $repository,
protected Squash $squash,
protected ForeignKeyMigration $foreignKeyMigration,
protected ProcedureMigration $procedureMigration,
protected TableMigration $tableMigration,
protected ViewMigration $viewMigration,
) {
parent::__construct();
}
protected MigrationRepositoryInterface $repository;
protected Squash $squash;
protected ForeignKeyMigration $foreignKeyMigration;
protected ProcedureMigration $procedureMigration;
protected ViewMigration $viewMigration;
protected TableMigration $tableMigration;

/**
* Execute the console command.
*
* @throws \Exception
*/
public function handle(): void
{
public function handle(
MigrationRepositoryInterface $repository,
Squash $squash,
ForeignKeyMigration $foreignKeyMigration,
ProcedureMigration $procedureMigration,
TableMigration $tableMigration,
ViewMigration $viewMigration,
): void {
$this->tableMigration = $tableMigration;
$this->viewMigration = $viewMigration;
$this->procedureMigration = $procedureMigration;
$this->foreignKeyMigration = $foreignKeyMigration;
$this->squash = $squash;
$this->repository = $repository;

$previousConnection = DB::getDefaultConnection();

try {
Expand Down
11 changes: 9 additions & 2 deletions tests/Feature/MySQL57/StackedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ public function testRunAsCall(): void
$this->assertTrue(Schema::hasTable('migration_table'));
$this->assertTrue(Schema::connection('migration2')->hasTable('migration2_table'));

$this->generateMigrations();
$this->generateMigrations([
'--table-filename' => 'create_migration_tables.php',
'--squash' => true,
]);

// Setting should reset.
$this->assertEquals(app(Setting::class), new Setting());

$this->generateMigrations(['--connection' => 'migration2']);
$this->generateMigrations([
'--connection' => 'migration2',
'--table-filename' => 'create_migration2_tables.php',
'--squash' => true,
]);

$files = File::files($this->getStorageMigrationsPath());
$this->assertCount(2, $files);
Expand Down

0 comments on commit 6dc429c

Please sign in to comment.