aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/BackgroundJob/TimedJobTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/BackgroundJob/TimedJobTest.php')
-rw-r--r--tests/lib/BackgroundJob/TimedJobTest.php90
1 files changed, 15 insertions, 75 deletions
diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php
index 12f1c43adde..d56240eb75e 100644
--- a/tests/lib/BackgroundJob/TimedJobTest.php
+++ b/tests/lib/BackgroundJob/TimedJobTest.php
@@ -1,117 +1,57 @@
<?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: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
-
-class TestTimedJob extends \OC\BackgroundJob\TimedJob {
- /** @var bool */
- public $ran = false;
-
- public function __construct() {
- $this->setInterval(10);
- }
-
- public function run($argument) {
- $this->ran = true;
- }
-}
-
-class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob {
- /** @var bool */
- public $ran = false;
-
- public function __construct(ITimeFactory $timeFactory) {
- parent::__construct($timeFactory);
- $this->setInterval(10);
- }
-
- public function run($argument) {
- $this->ran = true;
- }
-}
+use OCP\Server;
class TimedJobTest extends \Test\TestCase {
- /** @var DummyJobList $jobList */
- private $jobList;
-
- /** @var ITimeFactory */
- private $time;
+ private DummyJobList $jobList;
+ private ITimeFactory $time;
protected function setUp(): void {
parent::setUp();
$this->jobList = new DummyJobList();
- $this->time = \OC::$server->query(ITimeFactory::class);
+ $this->time = Server::get(ITimeFactory::class);
}
- public function testShouldRunAfterInterval() {
- $job = new TestTimedJob();
- $this->jobList->add($job);
-
- $job->setLastRun(time() - 12);
- $job->execute($this->jobList);
- $this->assertTrue($job->ran);
- }
-
- public function testShouldNotRunWithinInterval() {
- $job = new TestTimedJob();
- $this->jobList->add($job);
-
- $job->setLastRun(time() - 5);
- $job->execute($this->jobList);
- $this->assertFalse($job->ran);
- }
-
- public function testShouldNotTwice() {
- $job = new TestTimedJob();
- $this->jobList->add($job);
-
- $job->setLastRun(time() - 15);
- $job->execute($this->jobList);
- $this->assertTrue($job->ran);
- $job->ran = false;
- $job->execute($this->jobList);
- $this->assertFalse($job->ran);
- }
-
-
- public function testShouldRunAfterIntervalNew() {
+ public function testShouldRunAfterIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 12);
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertTrue($job->ran);
}
- public function testShouldNotRunWithinIntervalNew() {
+ public function testShouldNotRunWithinIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 5);
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertFalse($job->ran);
}
- public function testShouldNotTwiceNew() {
+ public function testShouldNotTwiceNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 15);
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertTrue($job->ran);
$job->ran = false;
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertFalse($job->ran);
}
}