diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index a9b3cfcc4942..3d5167ef82ba 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -266,6 +266,8 @@ protected function resolveCommand($command) * * @param \Throwable|string|null $exception * @return void + * + * @throws \Illuminate\Console\ManuallyFailedException|\Throwable */ public function fail(Throwable|string|null $exception = null) { diff --git a/tests/Integration/Console/CommandManualFailTest.php b/tests/Integration/Console/CommandManualFailTest.php index 4062139e0f3d..fd8bdd8c0674 100644 --- a/tests/Integration/Console/CommandManualFailTest.php +++ b/tests/Integration/Console/CommandManualFailTest.php @@ -28,6 +28,7 @@ public function testFailArtisanCommandManually() public function testCreatesAnExceptionFromString() { $this->expectException(ManuallyFailedException::class); + $this->expectExceptionMessage('Whoops!'); $command = new Command; $command->fail('Whoops!'); } @@ -35,9 +36,22 @@ public function testCreatesAnExceptionFromString() public function testCreatesAnExceptionFromNull() { $this->expectException(ManuallyFailedException::class); + $this->expectExceptionMessage('Command failed manually.'); $command = new Command; $command->fail(); } + + public function testThrowsTheOriginalThrowableInstance() + { + try { + $command = new Command; + $command->fail($original = new \RuntimeException('Something went wrong.')); + + $this->fail('Command::fail() method must throw the original throwable instance.'); + } catch (\Throwable $e) { + $this->assertSame($original, $e); + } + } } class FailingCommandStub extends Command