From 1076c91acafb27dff02479a259c7e28eb2d5b98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qu=E1=BB=B3nh=20Nguy=E1=BB=85n?= Date: Thu, 27 Jun 2024 03:51:00 +0700 Subject: [PATCH] Update Command::fail() dockblock and tests (#51914) --- src/Illuminate/Console/Command.php | 2 ++ .../Integration/Console/CommandManualFailTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+) 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