mirror of
https://github.com/flarum/core.git
synced 2025-08-05 07:57:46 +02:00
Do not catch exceptions when testing Console commands (#3813)
* Do not catch exceptions when testing Console commands This allows to easily test a case where a command should throw using `$this->expectException()`. * Rewrite ConsoleTest to use expectException Now that the ConsoleApplication is set to not catch exceptions. --------- Co-authored-by: IanM <16573496+imorland@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ use Flarum\Extend;
|
|||||||
use Flarum\Testing\integration\ConsoleTestCase;
|
use Flarum\Testing\integration\ConsoleTestCase;
|
||||||
use Illuminate\Console\Scheduling\Event;
|
use Illuminate\Console\Scheduling\Event;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||||
|
|
||||||
class ConsoleTest extends ConsoleTestCase
|
class ConsoleTest extends ConsoleTestCase
|
||||||
{
|
{
|
||||||
@@ -26,7 +27,8 @@ class ConsoleTest extends ConsoleTestCase
|
|||||||
'command' => 'customTestCommand'
|
'command' => 'customTestCommand'
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertEquals('Command "customTestCommand" is not defined.', $this->runCommand($input));
|
$this->expectException(CommandNotFoundException::class);
|
||||||
|
$this->runCommand($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,6 +23,7 @@ abstract class ConsoleTestCase extends TestCase
|
|||||||
if (is_null($this->console)) {
|
if (is_null($this->console)) {
|
||||||
$this->console = new ConsoleApplication('Flarum', Application::VERSION);
|
$this->console = new ConsoleApplication('Flarum', Application::VERSION);
|
||||||
$this->console->setAutoExit(false);
|
$this->console->setAutoExit(false);
|
||||||
|
$this->console->setCatchExceptions(false);
|
||||||
|
|
||||||
foreach ($this->app()->getConsoleCommands() as $command) {
|
foreach ($this->app()->getConsoleCommands() as $command) {
|
||||||
$this->console->add($command);
|
$this->console->add($command);
|
||||||
|
Reference in New Issue
Block a user