From a7d1814847b98bbb921a6481ea06cad5596cbfd5 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 7 Jun 2022 01:00:05 +1000 Subject: [PATCH] Allow assertions against pushed string based pushed jobs (#42676) --- src/Illuminate/Support/Testing/Fakes/QueueFake.php | 3 ++- tests/Support/SupportTestingQueueFakeTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Testing/Fakes/QueueFake.php b/src/Illuminate/Support/Testing/Fakes/QueueFake.php index cc161e613ba5..65e906bd02db 100644 --- a/src/Illuminate/Support/Testing/Fakes/QueueFake.php +++ b/src/Illuminate/Support/Testing/Fakes/QueueFake.php @@ -253,7 +253,7 @@ public function pushed($job, $callback = null) $callback = $callback ?: fn () => true; return collect($this->jobs[$job])->filter( - fn ($data) => $callback($data['job'], $data['queue']) + fn ($data) => $callback($data['job'], $data['queue'], $data['data']) )->pluck('job'); } @@ -306,6 +306,7 @@ public function push($job, $data = '', $queue = null) $this->jobs[is_object($job) ? get_class($job) : $job][] = [ 'job' => $job, 'queue' => $queue, + 'data' => $data, ]; } else { is_object($job) && isset($job->connection) diff --git a/tests/Support/SupportTestingQueueFakeTest.php b/tests/Support/SupportTestingQueueFakeTest.php index 049482452aaa..0873d767c621 100644 --- a/tests/Support/SupportTestingQueueFakeTest.php +++ b/tests/Support/SupportTestingQueueFakeTest.php @@ -52,6 +52,20 @@ public function testAssertPushed() $this->fake->assertPushed(JobStub::class); } + public function testItCanAssertAgainstDataWithPush() + { + $data = null; + $this->fake->push(JobStub::class, ['foo' => 'bar'], 'redis'); + + $this->fake->assertPushed(JobStub::class, function ($job, $queue, $jobData) use (&$data) { + $data = $jobData; + + return true; + }); + + $this->assertSame(['foo' => 'bar'], $data); + } + public function testAssertPushedWithIgnore() { $job = new JobStub;