diff --git a/src/Illuminate/Console/Scheduling/CallbackEvent.php b/src/Illuminate/Console/Scheduling/CallbackEvent.php index 96b1c1e1bfbd..45d0c2a3d324 100644 --- a/src/Illuminate/Console/Scheduling/CallbackEvent.php +++ b/src/Illuminate/Console/Scheduling/CallbackEvent.php @@ -2,6 +2,7 @@ namespace Illuminate\Console\Scheduling; +use Exception; use Illuminate\Contracts\Container\Container; use InvalidArgumentException; use LogicException; @@ -76,12 +77,18 @@ public function run(Container $container) $response = is_object($this->callback) ? $container->call([$this->callback, '__invoke'], $this->parameters) : $container->call($this->callback, $this->parameters); + } catch (Exception $e) { + $this->exitCode = 1; + + throw $e; } finally { $this->removeMutex(); parent::callAfterCallbacks($container); } + $this->exitCode = $response === false ? 1 : 0; + return $response; } diff --git a/tests/Console/Scheduling/CallbackEventTest.php b/tests/Console/Scheduling/CallbackEventTest.php new file mode 100644 index 000000000000..33c448e1e56c --- /dev/null +++ b/tests/Console/Scheduling/CallbackEventTest.php @@ -0,0 +1,63 @@ +run($this->app); + + $this->assertSame(0, $event->exitCode); + } + + public function testFalseResponseIsFailure() + { + $event = new CallbackEvent(m::mock(EventMutex::class), function () { + return false; + }); + + $event->run($this->app); + + $this->assertSame(1, $event->exitCode); + } + + public function testExceptionIsFailure() + { + $event = new CallbackEvent(m::mock(EventMutex::class), function () { + throw new \Exception; + }); + + try { + $event->run($this->app); + } catch (Exception $e) { + } + + $this->assertSame(1, $event->exitCode); + } + + public function testExceptionBubbles() + { + $event = new CallbackEvent(m::mock(EventMutex::class), function () { + throw new Exception; + }); + + $this->expectException(Exception::class); + + $event->run($this->app); + } +}