Skip to content

Commit

Permalink
Update Command::fail() dockblock and tests (#51914)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriquynh authored Jun 26, 2024
1 parent fe4f3dc commit 1076c91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/Console/CommandManualFailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,30 @@ public function testFailArtisanCommandManually()
public function testCreatesAnExceptionFromString()
{
$this->expectException(ManuallyFailedException::class);
$this->expectExceptionMessage('Whoops!');
$command = new Command;
$command->fail('Whoops!');
}

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
Expand Down

0 comments on commit 1076c91

Please sign in to comment.