File tree Expand file tree Collapse file tree 4 files changed +58
-8
lines changed Expand file tree Collapse file tree 4 files changed +58
-8
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,23 @@ public function testUpSuccess()
222
222
$ this ->artisan ('migrate:actions ' )->run ();
223
223
}
224
224
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
+
225
242
public function testPathAsFileWithExtension ()
226
243
{
227
244
$ this ->copyFiles ();
Original file line number Diff line number Diff line change @@ -13,12 +13,13 @@ protected function freshFiles(): void
13
13
);
14
14
}
15
15
16
- protected function copyFiles (): void
16
+ protected function copyFiles (bool $ failed = false ): void
17
17
{
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 ());
22
23
}
23
24
24
25
protected function copySuccessTransaction (): void
Original file line number Diff line number Diff line change 3
3
use DragonCode \LaravelActions \Support \Actionable ;
4
4
use Illuminate \Database \Query \Builder ;
5
5
use Illuminate \Support \Facades \DB ;
6
+ use Ramsey \Uuid \Uuid ;
6
7
7
8
class RunSuccess extends Actionable
8
9
{
9
10
public function up (): void
10
11
{
11
12
$ this ->table ()->insert ([
12
- 'value ' => ' foo ' ,
13
+ 'value ' => Uuid:: uuid4 () ,
13
14
]);
14
15
}
15
16
16
17
public function down (): void
17
18
{
18
19
$ this ->table ()->insert ([
19
- 'value ' => ' bar ' ,
20
+ 'value ' => Uuid:: uuid4 () ,
20
21
]);
21
22
}
22
23
23
24
public function success (): void
24
25
{
25
26
$ this ->table ()->insert ([
26
- 'value ' => ' success ' ,
27
+ 'value ' => Uuid:: uuid4 () ,
27
28
]);
28
29
}
29
30
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments