fix: Make DummyJobList.getJobsIterator return an interable instance

iterator_to_array on PHP 8.1 does not accept an array and fails hard with a type error

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Daniel Kesselberg 2025-07-02 18:34:13 +02:00
parent 8b1ac839d7
commit af38184b6f
No known key found for this signature in database
GPG key ID: 4A81C29F63464E8F

View file

@ -8,6 +8,7 @@
namespace Test\BackgroundJob;
use ArrayIterator;
use OC\BackgroundJob\JobList;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\Job;
@ -98,20 +99,23 @@ class DummyJobList extends JobList {
return $this->jobs;
}
public function getJobsIterator($job, ?int $limit, int $offset): array {
public function getJobsIterator($job, ?int $limit, int $offset): iterable {
if ($job instanceof IJob) {
$jobClass = get_class($job);
} else {
$jobClass = $job;
}
return array_slice(
$jobs = array_slice(
array_filter(
$this->jobs,
fn ($job) => ($jobClass === null) || (get_class($job) == $jobClass)
fn ($job) => ($jobClass === null) || (get_class($job) === $jobClass)
),
$offset,
$limit
);
return new ArrayIterator($jobs);
}
/**