aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/BackgroundJob/DummyJobList.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/BackgroundJob/DummyJobList.php')
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php41
1 files changed, 29 insertions, 12 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
index 64c0cf8038e..717db52715f 100644
--- a/tests/lib/BackgroundJob/DummyJobList.php
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -1,21 +1,24 @@
<?php
+
/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\BackgroundJob;
+use OC\BackgroundJob\JobList;
use OCP\BackgroundJob\IJob;
+use OCP\BackgroundJob\Job;
+use OCP\Server;
/**
* Class DummyJobList
*
* in memory job list for testing purposes
*/
-class DummyJobList extends \OC\BackgroundJob\JobList {
+class DummyJobList extends JobList {
/**
* @var IJob[]
*/
@@ -27,6 +30,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
private array $reserved = [];
private int $last = 0;
+ private int $lastId = 0;
public function __construct() {
}
@@ -38,9 +42,11 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
public function add($job, $argument = null, ?int $firstCheck = null): void {
if (is_string($job)) {
/** @var IJob $job */
- $job = \OCP\Server::get($job);
+ $job = Server::get($job);
}
$job->setArgument($argument);
+ $job->setId($this->lastId);
+ $this->lastId++;
if (!$this->has($job, null)) {
$this->jobs[] = $job;
}
@@ -55,9 +61,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;
+ }
}
}
@@ -100,7 +117,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
/**
* get the next job in the list
*/
- public function getNext(bool $onlyTimeSensitive = false): ?IJob {
+ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob {
if (count($this->jobs) > 0) {
if ($this->last < (count($this->jobs) - 1)) {
$i = $this->last + 1;
@@ -116,7 +133,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
/**
* set the job that was last ran
*
- * @param \OCP\BackgroundJob\Job $job
+ * @param Job $job
*/
public function setLastJob(IJob $job): void {
$i = array_search($job, $this->jobs);
@@ -127,7 +144,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;