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()
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 ();
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 33use DragonCode \LaravelActions \Support \Actionable ;
44use Illuminate \Database \Query \Builder ;
55use Illuminate \Support \Facades \DB ;
6+ use Ramsey \Uuid \Uuid ;
67
78class 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
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