Skip to content

Commit

Permalink
Allow assertions against pushed string based pushed jobs (#42676)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored Jun 6, 2022
1 parent 6cef8cb commit a7d1814
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/Support/SupportTestingQueueFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a7d1814

Please sign in to comment.