diff --git a/src/Illuminate/Console/Scheduling/CallbackEvent.php b/src/Illuminate/Console/Scheduling/CallbackEvent.php index a3ddfc634ff5..cf5c80f15764 100644 --- a/src/Illuminate/Console/Scheduling/CallbackEvent.php +++ b/src/Illuminate/Console/Scheduling/CallbackEvent.php @@ -77,6 +77,8 @@ public function run(Container $container) $response = is_object($this->callback) ? $container->call([$this->callback, '__invoke'], $this->parameters) : $container->call($this->callback, $this->parameters); + + $this->exitCode = $response === false ? 1 : 0; } catch (Throwable $e) { $this->exitCode = 1; @@ -87,8 +89,6 @@ public function run(Container $container) parent::callAfterCallbacks($container); } - $this->exitCode = $response === false ? 1 : 0; - return $response; } diff --git a/tests/Integration/Console/Scheduling/CallbackEventTest.php b/tests/Integration/Console/Scheduling/CallbackEventTest.php index 4d57a914c649..8b89512724c7 100644 --- a/tests/Integration/Console/Scheduling/CallbackEventTest.php +++ b/tests/Integration/Console/Scheduling/CallbackEventTest.php @@ -22,29 +22,47 @@ protected function tearDown(): void public function testDefaultResultIsSuccess() { - $event = new CallbackEvent(m::mock(EventMutex::class), function () { + $success = null; + + $event = (new CallbackEvent(m::mock(EventMutex::class), function () { + }))->onSuccess(function () use (&$success) { + $success = true; + })->onFailure(function () use (&$success) { + $success = false; }); $event->run($this->app); - $this->assertSame(0, $event->exitCode); + $this->assertTrue($success); } public function testFalseResponseIsFailure() { - $event = new CallbackEvent(m::mock(EventMutex::class), function () { + $success = null; + + $event = (new CallbackEvent(m::mock(EventMutex::class), function () { return false; + }))->onSuccess(function () use (&$success) { + $success = true; + })->onFailure(function () use (&$success) { + $success = false; }); $event->run($this->app); - $this->assertSame(1, $event->exitCode); + $this->assertFalse($success); } public function testExceptionIsFailure() { - $event = new CallbackEvent(m::mock(EventMutex::class), function () { + $success = null; + + $event = (new CallbackEvent(m::mock(EventMutex::class), function () { throw new \Exception; + }))->onSuccess(function () use (&$success) { + $success = true; + })->onFailure(function () use (&$success) { + $success = false; }); try { @@ -52,7 +70,7 @@ public function testExceptionIsFailure() } catch (Exception $e) { } - $this->assertSame(1, $event->exitCode); + $this->assertFalse($success); } public function testExceptionBubbles()