From 4a3e320b2253dda4c450e4804e2fc4ba247bd4c7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 30 May 2024 15:07:39 +0200 Subject: [PATCH] test: update DummyJobList Signed-off-by: Robin Appelman --- tests/lib/BackgroundJob/DummyJobList.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index 7886e8f877c0f..5d393aaf13a72 100644 --- a/tests/lib/BackgroundJob/DummyJobList.php +++ b/tests/lib/BackgroundJob/DummyJobList.php @@ -27,6 +27,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { private array $reserved = []; private int $last = 0; + private int $lastId = 0; public function __construct() { } @@ -41,6 +42,8 @@ public function add($job, $argument = null, int $firstCheck = null): void { $job = \OCP\Server::get($job); } $job->setArgument($argument); + $job->setId($this->lastId); + $this->lastId++; if (!$this->has($job, null)) { $this->jobs[] = $job; } @@ -55,9 +58,20 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi * @param mixed $argument */ public function remove($job, $argument = null): void { - $index = array_search($job, $this->jobs); - if ($index !== false) { - unset($this->jobs[$index]); + foreach ($this->jobs as $index => $listJob) { + if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) { + unset($this->jobs[$index]); + return; + } + } + } + + public function removeById(int $id): void { + foreach ($this->jobs as $index => $listJob) { + if ($listJob->getId() === $id) { + unset($this->jobs[$index]); + return; + } } } @@ -127,7 +141,7 @@ public function setLastJob(IJob $job): void { } } - public function getById(int $id): IJob { + public function getById(int $id): ?IJob { foreach ($this->jobs as $job) { if ($job->getId() === $id) { return $job;