Skip to content

Commit 5261d1d

Browse files
author
Andrey Helldar
committed
Reusable Launch Implementation Completed
1 parent ab25668 commit 5261d1d

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/Support/Actionable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@
77

88
abstract class Actionable extends Migration implements Contract
99
{
10+
/**
11+
* Determines the type of launch of the action.
12+
*
13+
* If true, then it will be executed once.
14+
* If false, then the action will run every time the `migrate:actions` command is invoked.
15+
*
16+
* @var bool
17+
*/
1018
protected $once = true;
1119

20+
/**
21+
* Determines the type of launch of the action.
22+
*
23+
* If true, then it will be executed once.
24+
* If false, then the action will run every time the `migrate:actions` command is invoked.
25+
*
26+
* @return bool
27+
*/
1228
public function isOnce(): bool
1329
{
1430
return $this->once;

tests/Commands/MigrateTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,35 @@ public function testMigrationCommand()
2424

2525
public function testEveryTimeExecution()
2626
{
27+
$this->copyFiles();
28+
2729
$table = 'every_time';
2830

29-
$this->artisan('migrate')->run();
3031
$this->artisan('migrate:actions:install')->run();
3132

3233
$this->assertDatabaseCount($table, 0);
3334
$this->assertDatabaseCount($this->table, 0);
35+
$this->assertDatabaseMigrationDoesntLike($this->table, 'every_time');
3436
$this->artisan('migrate:actions')->run();
3537

3638
$this->assertDatabaseCount($table, 1);
3739
$this->assertDatabaseCount($this->table, 1);
40+
$this->assertDatabaseMigrationDoesntLike($this->table, 'every_time');
3841
$this->artisan('migrate:actions')->run();
3942

4043
$this->assertDatabaseCount($table, 2);
4144
$this->assertDatabaseCount($this->table, 1);
45+
$this->assertDatabaseMigrationDoesntLike($this->table, 'every_time');
46+
$this->artisan('migrate:actions')->run();
47+
48+
$this->assertDatabaseCount($table, 3);
49+
$this->assertDatabaseCount($this->table, 1);
50+
$this->assertDatabaseMigrationDoesntLike($this->table, 'every_time');
51+
$this->artisan('migrate:actions')->run();
52+
53+
$this->assertDatabaseCount($table, 4);
54+
$this->assertDatabaseCount($this->table, 1);
55+
$this->assertDatabaseMigrationDoesntLike($this->table, 'every_time');
4256
}
4357

4458
public function testMigrationNotFound()

tests/Concerns/AssertDatabase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected function assertDatabaseDoesntTable(string $table): void
2929
);
3030
}
3131

32+
protected function assertDatabaseMigrationHas(string $table, $value, $connection = null): void
33+
{
34+
$this->assertDatabaseHasLike($table, 'migration', $value, $connection);
35+
}
36+
3237
protected function assertDatabaseHasLike(string $table, string $column, $value, $connection = null): void
3338
{
3439
$exists = DB::connection($connection)
@@ -39,6 +44,11 @@ protected function assertDatabaseHasLike(string $table, string $column, $value,
3944
$this->assertTrue($exists);
4045
}
4146

47+
protected function assertDatabaseMigrationDoesntLike(string $table, $value, $connection = null): void
48+
{
49+
$this->assertDatabaseDoesntLike($table, 'migration', $value, $connection);
50+
}
51+
4252
protected function assertDatabaseDoesntLike(string $table, string $column, $value, $connection = null): void
4353
{
4454
$exists = DB::connection($connection)

tests/Concerns/Files.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66

77
trait Files
88
{
9-
protected function freshFiles()
9+
protected function freshFiles(): void
1010
{
1111
File::deleteDirectory(
1212
database_path('actions')
1313
);
1414
}
15+
16+
protected function copyFiles(): void
17+
{
18+
File::copyDirectory(
19+
__DIR__ . '/../fixtures/actions',
20+
database_path('actions')
21+
);
22+
}
1523
}

0 commit comments

Comments
 (0)