Skip to content

Commit 6d760e6

Browse files
author
Andrey Helldar
committed
Added test
1 parent 58ee8c3 commit 6d760e6

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

tests/Commands/MigrateTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,23 @@ public function testUpSuccess()
222222
$this->artisan('migrate:actions')->run();
223223
}
224224

225+
public function testUpSuccessOnFailed()
226+
{
227+
$this->expectException(Exception::class);
228+
$this->expectExceptionMessage('Custom exception');
229+
230+
$this->copyFiles(true);
231+
232+
$table = 'success';
233+
234+
$this->artisan('migrate:actions:install')->run();
235+
236+
$this->assertDatabaseCount($table, 0);
237+
$this->assertDatabaseCount($this->table, 0);
238+
$this->assertDatabaseMigrationDoesntLike($this->table, 'run_success');
239+
$this->artisan('migrate:actions')->run();
240+
}
241+
225242
public function testPathAsFileWithExtension()
226243
{
227244
$this->copyFiles();

tests/Concerns/Files.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ protected function freshFiles(): void
1313
);
1414
}
1515

16-
protected function copyFiles(): void
16+
protected function copyFiles(bool $failed = false): void
1717
{
18-
File::copyDirectory(
19-
__DIR__ . '/../fixtures/actions',
20-
$this->targetDirectory()
21-
);
18+
$source = $failed
19+
? __DIR__ . '/../fixtures/actions_failed'
20+
: __DIR__ . '/../fixtures/actions';
21+
22+
File::copyDirectory($source, $this->targetDirectory());
2223
}
2324

2425
protected function copySuccessTransaction(): void

tests/fixtures/actions/2021_12_23_165047_run_success.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
use DragonCode\LaravelActions\Support\Actionable;
44
use Illuminate\Database\Query\Builder;
55
use Illuminate\Support\Facades\DB;
6+
use Ramsey\Uuid\Uuid;
67

78
class RunSuccess extends Actionable
89
{
910
public function up(): void
1011
{
1112
$this->table()->insert([
12-
'value' => 'foo',
13+
'value' => Uuid::uuid4(),
1314
]);
1415
}
1516

1617
public function down(): void
1718
{
1819
$this->table()->insert([
19-
'value' => 'bar',
20+
'value' => Uuid::uuid4(),
2021
]);
2122
}
2223

2324
public function success(): void
2425
{
2526
$this->table()->insert([
26-
'value' => 'success',
27+
'value' => Uuid::uuid4(),
2728
]);
2829
}
2930

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use DragonCode\LaravelActions\Support\Actionable;
4+
use Illuminate\Database\Query\Builder;
5+
use Illuminate\Support\Facades\DB;
6+
use Ramsey\Uuid\Uuid;
7+
8+
class RunSuccessOnFailed extends Actionable
9+
{
10+
public function up(): void
11+
{
12+
throw new Exception('Custom exception');
13+
}
14+
15+
public function down(): void
16+
{
17+
throw new Exception();
18+
}
19+
20+
public function success(): void
21+
{
22+
$this->table()->insert([
23+
'value' => Uuid::uuid4(),
24+
]);
25+
}
26+
27+
protected function table(): Builder
28+
{
29+
return DB::table('success');
30+
}
31+
}

0 commit comments

Comments
 (0)