-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ 11.x ] Adds ability to manually fail a command from outside the han…
…dle() method (#51435) * Add ManuallyFailedException to Console * set up tests for manually failing a command * implement manual test failing * lint * fixes and formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
3d800c5
commit f8c0f59
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console; | ||
|
||
use RuntimeException; | ||
|
||
class ManuallyFailedException extends RuntimeException | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Console; | ||
|
||
use Illuminate\Console\Application as Artisan; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Console\ManuallyFailedException; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class CommandManualFailTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
Artisan::starting(function ($artisan) { | ||
$artisan->resolveCommands([ | ||
FailingCommandStub::class, | ||
]); | ||
}); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testFailArtisanCommandManually() | ||
{ | ||
$this->artisan('app:fail')->assertFailed(); | ||
} | ||
|
||
public function testCreatesAnExceptionFromString() | ||
{ | ||
$this->expectException(ManuallyFailedException::class); | ||
$command = new Command; | ||
$command->fail('Whoops!'); | ||
} | ||
|
||
public function testCreatesAnExceptionFromNull() | ||
{ | ||
$this->expectException(ManuallyFailedException::class); | ||
$command = new Command; | ||
$command->fail(); | ||
} | ||
} | ||
|
||
class FailingCommandStub extends Command | ||
{ | ||
protected $signature = 'app:fail'; | ||
|
||
public function handle() | ||
{ | ||
$this->trigger_failure(); | ||
|
||
// This should never be reached. | ||
return static::SUCCESS; | ||
} | ||
|
||
protected function trigger_failure() | ||
{ | ||
$this->fail('Whoops!'); | ||
} | ||
} |