diff options
author | Robin Appelman <robin@icewind.nl> | 2024-05-30 15:07:39 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-06-17 13:25:03 +0200 |
commit | 1b346aa9a4c3d73919e6fa5123e4a3fb394aa8d6 (patch) | |
tree | bb41c7853461deb17a634168db03caa6b414520b /tests | |
parent | 40442f533701380c6ef68d69cb818e1211ad20c4 (diff) | |
download | nextcloud-server-1b346aa9a4c3d73919e6fa5123e4a3fb394aa8d6.tar.gz nextcloud-server-1b346aa9a4c3d73919e6fa5123e4a3fb394aa8d6.zip |
test: update DummyJobList
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/BackgroundJob/DummyJobList.php | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index 7886e8f877c..5d393aaf13a 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 @@ class DummyJobList extends \OC\BackgroundJob\JobList { $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 @@ class DummyJobList extends \OC\BackgroundJob\JobList { * @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 @@ class DummyJobList extends \OC\BackgroundJob\JobList { } } - public function getById(int $id): IJob { + public function getById(int $id): ?IJob { foreach ($this->jobs as $job) { if ($job->getId() === $id) { return $job; |