summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-06-27 12:06:23 +0200
committerCôme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com>2022-07-11 09:46:23 +0000
commit50a7f612d9a3e1bc25b989f8efa3a34780e86726 (patch)
tree2ecdd1b2cc51a69aee772ffdee2619f4b80d3055 /tests
parent868d748dbfa51461b5ee7cc827be6f314ae0959d (diff)
downloadnextcloud-server-50a7f612d9a3e1bc25b989f8efa3a34780e86726.tar.gz
nextcloud-server-50a7f612d9a3e1bc25b989f8efa3a34780e86726.zip
Fix DummyJobList class used by tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php44
1 files changed, 27 insertions, 17 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
index 0751409f62c..d8ec0479c78 100644
--- a/tests/lib/BackgroundJob/DummyJobList.php
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -19,20 +19,20 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
/**
* @var IJob[]
*/
- private $jobs = [];
+ private array $jobs = [];
- private $last = 0;
+ private int $last = 0;
public function __construct() {
}
/**
- * @param IJob|string $job
+ * @param IJob|class-string<IJob> $job
* @param mixed $argument
*/
- public function add($job, $argument = null) {
+ public function add($job, $argument = null): void {
if (is_string($job)) {
- /** @var \OC\BackgroundJob\Job $job */
+ /** @var IJob $job */
$job = new $job;
}
$job->setArgument($argument);
@@ -45,7 +45,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
* @param IJob|string $job
* @param mixed $argument
*/
- public function remove($job, $argument = null) {
+ public function remove($job, $argument = null): void {
$index = array_search($job, $this->jobs);
if ($index !== false) {
unset($this->jobs[$index]);
@@ -59,7 +59,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
* @param mixed $argument
* @return bool
*/
- public function has($job, $argument) {
+ public function has($job, $argument): bool {
return array_search($job, $this->jobs) !== false;
}
@@ -72,6 +72,22 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
return $this->jobs;
}
+ public function getJobs($job, ?int $limit, int $offset): array {
+ if ($job instanceof IJob) {
+ $jobClass = get_class($job);
+ } else {
+ $jobClass = $job;
+ }
+ return array_slice(
+ array_filter(
+ $this->jobs,
+ fn ($job) => ($jobClass === null) || (get_class($job) == $jobClass)
+ ),
+ $offset,
+ $limit
+ );
+ }
+
/**
* get the next job in the list
*
@@ -96,7 +112,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
*
* @param \OC\BackgroundJob\Job $job
*/
- public function setLastJob(IJob $job) {
+ public function setLastJob(IJob $job): void {
$i = array_search($job, $this->jobs);
if ($i !== false) {
$this->last = $i;
@@ -107,9 +123,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
/**
* @param int $id
- * @return IJob
*/
- public function getById($id) {
+ public function getById($id): IJob {
foreach ($this->jobs as $job) {
if ($job->getId() === $id) {
return $job;
@@ -122,16 +137,11 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
return null;
}
- /**
- * set the lastRun of $job to now
- *
- * @param IJob $job
- */
- public function setLastRun(IJob $job) {
+ public function setLastRun(IJob $job): void {
$job->setLastRun(time());
}
- public function setExecutionTime(IJob $job, $timeTaken) {
+ public function setExecutionTime(IJob $job, $timeTaken): void {
}
public function resetBackgroundJob(IJob $job): void {