File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
tests/Integration/Testing Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,16 @@ public function assertSuccessful()
249249 return $ this ->assertExitCode (Command::SUCCESS );
250250 }
251251
252+ /**
253+ * Assert that the command has the success exit code.
254+ *
255+ * @return $this
256+ */
257+ public function assertOk ()
258+ {
259+ return $ this ->assertSuccessful ();
260+ }
261+
252262 /**
253263 * Assert that the command does not have the success exit code.
254264 *
Original file line number Diff line number Diff line change @@ -33,12 +33,27 @@ protected function setUp(): void
3333 $ this ->line ($ this ->ask ('Huh? ' ));
3434 });
3535
36+ Artisan::command ('exit {code} ' , fn () => (int ) $ this ->argument ('code ' ));
37+
3638 Artisan::command ('contains ' , function () {
3739 $ this ->line ('My name is Taylor Otwell ' );
3840 });
3941 }
4042
4143 public function test_console_command_that_passes ()
44+ {
45+ $ this ->artisan ('exit ' , ['code ' => 0 ])->assertOk ();
46+ }
47+
48+ public function test_console_command_that_fails ()
49+ {
50+ $ this ->expectException (AssertionFailedError::class);
51+ $ this ->expectExceptionMessage ('Expected status code 0 but received 1. ' );
52+
53+ $ this ->artisan ('exit ' , ['code ' => 1 ])->assertOk ();
54+ }
55+
56+ public function test_console_command_that_passes_with_output ()
4257 {
4358 $ this ->artisan ('survey ' )
4459 ->expectsQuestion ('What is your name? ' , 'Taylor Otwell ' )
You can’t perform that action at this time.
0 commit comments