From 3789636af9d4eb246be526d9e54563a325e5eb97 Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Tue, 17 Dec 2024 22:15:19 +0100 Subject: [PATCH 1/3] Add `getJob()` method to `PendingDispatch` class + tests --- .../Foundation/Bus/PendingDispatch.php | 10 ++ tests/Bus/BusPendingDispatchTest.php | 117 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/Bus/BusPendingDispatchTest.php diff --git a/src/Illuminate/Foundation/Bus/PendingDispatch.php b/src/Illuminate/Foundation/Bus/PendingDispatch.php index 97a339a00946..b675184508d8 100644 --- a/src/Illuminate/Foundation/Bus/PendingDispatch.php +++ b/src/Illuminate/Foundation/Bus/PendingDispatch.php @@ -161,6 +161,16 @@ public function afterResponse() return $this; } + /** + * Get the underlying job instance. + * + * @var mixed + */ + public function getJob() + { + return $this->job; + } + /** * Determine if the job should be dispatched. * diff --git a/tests/Bus/BusPendingDispatchTest.php b/tests/Bus/BusPendingDispatchTest.php new file mode 100644 index 000000000000..bc13988b8788 --- /dev/null +++ b/tests/Bus/BusPendingDispatchTest.php @@ -0,0 +1,117 @@ +job = m::mock(stdClass::class); + $this->pendingDispatch = new PendingDispatchWithoutDestructor($this->job); + + parent::setUp(); + } + + protected function tearDown(): void + { + parent::tearDown(); + + m::close(); + } + + public function testOnConnection() + { + $this->job->shouldReceive('onConnection')->once()->with('test-connection'); + $this->pendingDispatch->onConnection('test-connection'); + } + + public function testOnQueue() + { + $this->job->shouldReceive('onQueue')->once()->with('test-queue'); + $this->pendingDispatch->onQueue('test-queue'); + } + + public function testAllOnConnection() + { + $this->job->shouldReceive('allOnConnection')->once()->with('test-connection'); + $this->pendingDispatch->allOnConnection('test-connection'); + } + + public function testAllOnQueue() + { + $this->job->shouldReceive('allOnQueue')->once()->with('test-queue'); + $this->pendingDispatch->allOnQueue('test-queue'); + } + + public function testDelay() + { + $this->job->shouldReceive('delay')->once()->with(60); + $this->pendingDispatch->delay(60); + } + + public function testWithoutDelay() + { + $this->job->shouldReceive('withoutDelay')->once(); + $this->pendingDispatch->withoutDelay(); + } + + public function testAfterCommit() + { + $this->job->shouldReceive('afterCommit')->once(); + $this->pendingDispatch->afterCommit(); + } + + public function testBeforeCommit() + { + $this->job->shouldReceive('beforeCommit')->once(); + $this->pendingDispatch->beforeCommit(); + } + + public function testChain() + { + $chain = [new stdClass]; + $this->job->shouldReceive('chain')->once()->with($chain); + $this->pendingDispatch->chain($chain); + } + + public function testAfterResponse() + { + $this->pendingDispatch->afterResponse(); + $this->assertTrue( + (new ReflectionClass($this->pendingDispatch))->getProperty('afterResponse')->getValue($this->pendingDispatch) + ); + } + + public function testGetJob() + { + $this->assertSame($this->job, $this->pendingDispatch->getJob()); + } + + public function testDynamicallyProxyMethods() + { + $newJob = m::mock(stdClass::class); + $this->job->shouldReceive('appendToChain')->once()->with($newJob); + $this->pendingDispatch->appendToChain($newJob); + } +} \ No newline at end of file From 4dd66e1a01208a8c67415403190eb0966b210ed3 Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Tue, 17 Dec 2024 22:20:19 +0100 Subject: [PATCH 2/3] Fix styling --- tests/Bus/BusPendingDispatchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Bus/BusPendingDispatchTest.php b/tests/Bus/BusPendingDispatchTest.php index bc13988b8788..99c4065cb5c5 100644 --- a/tests/Bus/BusPendingDispatchTest.php +++ b/tests/Bus/BusPendingDispatchTest.php @@ -114,4 +114,4 @@ public function testDynamicallyProxyMethods() $this->job->shouldReceive('appendToChain')->once()->with($newJob); $this->pendingDispatch->appendToChain($newJob); } -} \ No newline at end of file +} From d01186a7d21dadb28367411ea6cb4b8330d2dbf1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 17 Dec 2024 15:24:55 -0600 Subject: [PATCH 3/3] Update PendingDispatch.php --- .../Foundation/Bus/PendingDispatch.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Foundation/Bus/PendingDispatch.php b/src/Illuminate/Foundation/Bus/PendingDispatch.php index b675184508d8..361454214d95 100644 --- a/src/Illuminate/Foundation/Bus/PendingDispatch.php +++ b/src/Illuminate/Foundation/Bus/PendingDispatch.php @@ -161,16 +161,6 @@ public function afterResponse() return $this; } - /** - * Get the underlying job instance. - * - * @var mixed - */ - public function getJob() - { - return $this->job; - } - /** * Determine if the job should be dispatched. * @@ -186,6 +176,16 @@ protected function shouldDispatch() ->acquire($this->job); } + /** + * Get the underlying job instance. + * + * @var mixed + */ + public function getJob() + { + return $this->job; + } + /** * Dynamically proxy methods to the underlying job. *