summaryrefslogtreecommitdiffstats
path: root/tests/lib/BackgroundJob/DummyJobList.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-05-20 15:38:20 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-20 15:38:20 +0200
commit94ad54ec9b96d41a614fbbad4a97b34c41a6901f (patch)
treef3eb7cdda2704aaf0cd59d58efe66bcbd34cb67d /tests/lib/BackgroundJob/DummyJobList.php
parent2ef751b1ec28f7b5c7113af60ec8c9fa0ae1cf87 (diff)
downloadnextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.tar.gz
nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.zip
Move tests/ to PSR-4 (#24731)
* Move a-b to PSR-4 * Move c-d to PSR-4 * Move e+g to PSR-4 * Move h-l to PSR-4 * Move m-r to PSR-4 * Move s-u to PSR-4 * Move files/ to PSR-4 * Move remaining tests to PSR-4 * Remove Test\ from old autoloader
Diffstat (limited to 'tests/lib/BackgroundJob/DummyJobList.php')
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
new file mode 100644
index 00000000000..6cc690fd553
--- /dev/null
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -0,0 +1,135 @@
+<?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.
+ */
+
+namespace Test\BackgroundJob;
+
+/**
+ * Class DummyJobList
+ *
+ * in memory job list for testing purposes
+ */
+class DummyJobList extends \OC\BackgroundJob\JobList {
+ /**
+ * @var \OC\BackgroundJob\Job[]
+ */
+ private $jobs = array();
+
+ private $last = 0;
+
+ public function __construct() {
+ }
+
+ /**
+ * @param \OC\BackgroundJob\Job|string $job
+ * @param mixed $argument
+ */
+ public function add($job, $argument = null) {
+ if (is_string($job)) {
+ /** @var \OC\BackgroundJob\Job $job */
+ $job = new $job;
+ }
+ $job->setArgument($argument);
+ if (!$this->has($job, null)) {
+ $this->jobs[] = $job;
+ }
+ }
+
+ /**
+ * @param \OC\BackgroundJob\Job|string $job
+ * @param mixed $argument
+ */
+ public function remove($job, $argument = null) {
+ $index = array_search($job, $this->jobs);
+ if ($index !== false) {
+ unset($this->jobs[$index]);
+ }
+ }
+
+ /**
+ * check if a job is in the list
+ *
+ * @param $job
+ * @param mixed $argument
+ * @return bool
+ */
+ public function has($job, $argument) {
+ return array_search($job, $this->jobs) !== false;
+ }
+
+ /**
+ * get all jobs in the list
+ *
+ * @return \OC\BackgroundJob\Job[]
+ */
+ public function getAll() {
+ return $this->jobs;
+ }
+
+ /**
+ * get the next job in the list
+ *
+ * @return \OC\BackgroundJob\Job
+ */
+ public function getNext() {
+ if (count($this->jobs) > 0) {
+ if ($this->last < (count($this->jobs) - 1)) {
+ $i = $this->last + 1;
+ } else {
+ $i = 0;
+ }
+ return $this->jobs[$i];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * set the job that was last ran
+ *
+ * @param \OC\BackgroundJob\Job $job
+ */
+ public function setLastJob($job) {
+ $i = array_search($job, $this->jobs);
+ if ($i !== false) {
+ $this->last = $i;
+ } else {
+ $this->last = 0;
+ }
+ }
+
+ /**
+ * @param int $id
+ * @return Job
+ */
+ public function getById($id) {
+ foreach ($this->jobs as $job) {
+ if ($job->getId() === $id) {
+ return $job;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get the id of the last ran job
+ *
+ * @return int
+ */
+ public function getLastJob() {
+ return $this->last;
+ }
+
+ /**
+ * set the lastRun of $job to now
+ *
+ * @param \OC\BackgroundJob\Job $job
+ */
+ public function setLastRun($job) {
+ $job->setLastRun(time());
+ }
+}