From ee38413552bf4a8b911e4ddfc4bb1a505464f6c3 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 19 Sep 2020 19:46:37 -0400 Subject: [PATCH 1/3] set the exit code before callbacks run. update test. --- .../Console/Scheduling/CallbackEvent.php | 4 +-- .../Console/Scheduling/CallbackEventTest.php | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) 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..29dae7c777c3 100644 --- a/tests/Integration/Console/Scheduling/CallbackEventTest.php +++ b/tests/Integration/Console/Scheduling/CallbackEventTest.php @@ -22,29 +22,48 @@ 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 +71,7 @@ public function testExceptionIsFailure() } catch (Exception $e) { } - $this->assertSame(1, $event->exitCode); + $this->assertFalse($success); } public function testExceptionBubbles() From 40ebecafc0d5c29c232da7114878a66aa351af6a Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 19 Sep 2020 19:55:00 -0400 Subject: [PATCH 2/3] styleci --- .../Console/Scheduling/CallbackEventTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Integration/Console/Scheduling/CallbackEventTest.php b/tests/Integration/Console/Scheduling/CallbackEventTest.php index 29dae7c777c3..f678b28fa75d 100644 --- a/tests/Integration/Console/Scheduling/CallbackEventTest.php +++ b/tests/Integration/Console/Scheduling/CallbackEventTest.php @@ -26,9 +26,9 @@ public function testDefaultResultIsSuccess() $event = (new CallbackEvent(m::mock(EventMutex::class), function () { - }))->onSuccess(function () use ( &$success ) { + }))->onSuccess(function () use (&$success) { $success = true; - })->onFailure(function () use ( &$success ) { + })->onFailure(function () use (&$success) { $success = false; }); @@ -43,9 +43,9 @@ public function testFalseResponseIsFailure() $event = (new CallbackEvent(m::mock(EventMutex::class), function () { return false; - }))->onSuccess(function () use ( &$success ) { + }))->onSuccess(function () use (&$success) { $success = true; - })->onFailure(function () use ( &$success ) { + })->onFailure(function () use (&$success) { $success = false; }); @@ -60,9 +60,9 @@ public function testExceptionIsFailure() $event = (new CallbackEvent(m::mock(EventMutex::class), function () { throw new \Exception; - }))->onSuccess(function () use ( &$success ) { + }))->onSuccess(function () use (&$success) { $success = true; - })->onFailure(function () use ( &$success ) { + })->onFailure(function () use (&$success) { $success = false; }); From 04754448d3f67e0245e4455c158b9df114cc1933 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 19 Sep 2020 19:55:36 -0400 Subject: [PATCH 3/3] styleci --- tests/Integration/Console/Scheduling/CallbackEventTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Console/Scheduling/CallbackEventTest.php b/tests/Integration/Console/Scheduling/CallbackEventTest.php index f678b28fa75d..8b89512724c7 100644 --- a/tests/Integration/Console/Scheduling/CallbackEventTest.php +++ b/tests/Integration/Console/Scheduling/CallbackEventTest.php @@ -25,7 +25,6 @@ public function testDefaultResultIsSuccess() $success = null; $event = (new CallbackEvent(m::mock(EventMutex::class), function () { - }))->onSuccess(function () use (&$success) { $success = true; })->onFailure(function () use (&$success) {