Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\Jobs\InspectedJob;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\ReflectsClosures;
Expand Down Expand Up @@ -573,7 +574,7 @@ protected function inspectJobs(array $jobs): Collection
: $data['job'],
attempts: 0,
payload: [],
createdAt: null,
createdAt: isset($data['createdAt']) ? Carbon::createFromTimestamp($data['createdAt']) : null,
));
}

Expand All @@ -595,7 +596,10 @@ public function allReservedJobs(): Collection
*/
public function creationTimeOfOldestPendingJob($queue = null)
{
return null;
return (new Collection($this->jobs))
->flatten(1)
->whereStrict('queue', enum_value($queue))
->min('createdAt');
}

/**
Expand Down Expand Up @@ -623,6 +627,7 @@ public function push($job, $data = '', $queue = null)
'job' => $this->serializeAndRestore ? $this->serializeAndRestoreJob($job) : $job,
'queue' => $queue,
'data' => $data,
'createdAt' => Carbon::now()->getTimestamp(),
];

if ($job instanceof ShouldBeUnique) {
Expand Down Expand Up @@ -711,6 +716,7 @@ public function later($delay, $job, $data = '', $queue = null)
$this->delayed[is_object($job) ? get_class($job) : $job][] = [
'job' => $job,
'queue' => enum_value($queue),
'createdAt' => Carbon::now()->getTimestamp(),
];
}

Expand Down Expand Up @@ -762,6 +768,7 @@ public function reserve($job, $queue = null)
$this->reserved[is_object($job) ? get_class($job) : $job][] = [
'job' => $this->serializeAndRestore ? $this->serializeAndRestoreJob($job) : $job,
'queue' => $queue,
'createdAt' => Carbon::now()->getTimestamp(),
];
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Support/SupportTestingQueueFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\Jobs\InspectedJob;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Mockery as m;
use PHPUnit\Framework\ExpectationFailedException;
Expand Down Expand Up @@ -650,6 +651,23 @@ public function testDelayedJobsAreStillPushed()
$this->fake->assertPushedOn('foo', JobStub::class);
}

public function testCreationTimeOfOldestPendingJob()
{
Carbon::setTestNow($now = Carbon::now());

$this->assertNull($this->fake->creationTimeOfOldestPendingJob('foo'));

$this->fake->push($this->job, '', 'foo');

Carbon::setTestNow($now->copy()->addMinutes(5));

$this->fake->push(new JobToFakeStub, '', 'foo');

$this->assertSame($now->getTimestamp(), $this->fake->creationTimeOfOldestPendingJob('foo'));

Carbon::setTestNow();
}

public function testReservedJobs()
{
$this->fake->reserve($this->job, 'foo');
Expand Down