aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/BackgroundJob
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-02-06 12:02:54 +0100
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-02-08 10:28:29 +0100
commit65981f99bfaa4f05469b32eaf0faa21e3b01d812 (patch)
tree7f01e10ae5cfd3b11cd478260a2bbf56936b5086 /tests/lib/BackgroundJob
parent166773879ba20bf7b81f3996a7c4e2a9ff7ee16d (diff)
downloadnextcloud-server-65981f99bfaa4f05469b32eaf0faa21e3b01d812.tar.gz
nextcloud-server-65981f99bfaa4f05469b32eaf0faa21e3b01d812.zip
chore: Migrate away from internal Job classes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/lib/BackgroundJob')
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php2
-rw-r--r--tests/lib/BackgroundJob/JobTest.php22
-rw-r--r--tests/lib/BackgroundJob/QueuedJobTest.php34
-rw-r--r--tests/lib/BackgroundJob/TestJob.php2
-rw-r--r--tests/lib/BackgroundJob/TimedJobTest.php67
5 files changed, 28 insertions, 99 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
index 7886e8f877c..05a9e5928c2 100644
--- a/tests/lib/BackgroundJob/DummyJobList.php
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -116,7 +116,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
/**
* set the job that was last ran
*
- * @param \OC\BackgroundJob\Job $job
+ * @param \OCP\BackgroundJob\Job $job
*/
public function setLastJob(IJob $job): void {
$i = array_search($job, $this->jobs);
diff --git a/tests/lib/BackgroundJob/JobTest.php b/tests/lib/BackgroundJob/JobTest.php
index a4e0dcf4fd6..c3a4a7d0552 100644
--- a/tests/lib/BackgroundJob/JobTest.php
+++ b/tests/lib/BackgroundJob/JobTest.php
@@ -9,16 +9,20 @@
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class JobTest extends \Test\TestCase {
private $run = false;
private ITimeFactory $timeFactory;
+ private LoggerInterface $logger;
protected function setUp(): void {
parent::setUp();
$this->run = false;
- $this->timeFactory = \OC::$server->get(ITimeFactory::class);
+ $this->timeFactory = \OCP\Server::get(ITimeFactory::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+
+ \OC::$server->registerService(LoggerInterface::class, fn ($c) => $this->logger);
}
public function testRemoveAfterException() {
@@ -29,14 +33,11 @@ class JobTest extends \Test\TestCase {
});
$jobList->add($job);
- $logger = $this->getMockBuilder(ILogger::class)
- ->disableOriginalConstructor()
- ->getMock();
- $logger->expects($this->once())
+ $this->logger->expects($this->once())
->method('error');
$this->assertCount(1, $jobList->getAll());
- $job->execute($jobList, $logger);
+ $job->start($jobList);
$this->assertTrue($this->run);
$this->assertCount(1, $jobList->getAll());
}
@@ -49,14 +50,11 @@ class JobTest extends \Test\TestCase {
});
$jobList->add($job);
- $logger = $this->getMockBuilder(ILogger::class)
- ->disableOriginalConstructor()
- ->getMock();
- $logger->expects($this->once())
+ $this->logger->expects($this->once())
->method('error');
$this->assertCount(1, $jobList->getAll());
- $job->execute($jobList, $logger);
+ $job->start($jobList);
$this->assertTrue($this->run);
$this->assertCount(1, $jobList->getAll());
}
diff --git a/tests/lib/BackgroundJob/QueuedJobTest.php b/tests/lib/BackgroundJob/QueuedJobTest.php
index 9378816ce61..aaf24957f09 100644
--- a/tests/lib/BackgroundJob/QueuedJobTest.php
+++ b/tests/lib/BackgroundJob/QueuedJobTest.php
@@ -9,20 +9,10 @@
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
-class TestQueuedJob extends \OC\BackgroundJob\QueuedJob {
- public $ran = false;
-
-
- public function run($argument) {
- $this->ran = true;
- }
-}
-
-
-class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob {
- public $ran = false;
-
+class TestQueuedJobNew extends QueuedJob {
+ public bool $ran = false;
public function run($argument) {
$this->ran = true;
@@ -30,10 +20,7 @@ class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob {
}
class QueuedJobTest extends \Test\TestCase {
- /**
- * @var DummyJobList $jobList
- */
- private $jobList;
+ private DummyJobList $jobList;
protected function setUp(): void {
parent::setUp();
@@ -41,22 +28,13 @@ class QueuedJobTest extends \Test\TestCase {
$this->jobList = new DummyJobList();
}
- public function testJobShouldBeRemoved() {
- $job = new TestQueuedJob();
- $this->jobList->add($job);
-
- $this->assertTrue($this->jobList->has($job, null));
- $job->execute($this->jobList);
- $this->assertTrue($job->ran);
- }
-
public function testJobShouldBeRemovedNew() {
- $job = new TestQueuedJobNew(\OC::$server->query(ITimeFactory::class));
+ $job = new TestQueuedJobNew(\OCP\Server::get(ITimeFactory::class));
$job->setId(42);
$this->jobList->add($job);
$this->assertTrue($this->jobList->has($job, null));
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertTrue($job->ran);
}
}
diff --git a/tests/lib/BackgroundJob/TestJob.php b/tests/lib/BackgroundJob/TestJob.php
index cc7a4651c4b..54b0ec7d9ea 100644
--- a/tests/lib/BackgroundJob/TestJob.php
+++ b/tests/lib/BackgroundJob/TestJob.php
@@ -23,7 +23,7 @@ class TestJob extends \OCP\BackgroundJob\Job {
* @param callable $callback
*/
public function __construct(ITimeFactory $time = null, $testCase = null, $callback = null) {
- parent::__construct($time ?? \OC::$server->get(ITimeFactory::class));
+ parent::__construct($time ?? \OCP\Server::get(ITimeFactory::class));
$this->testCase = $testCase;
$this->callback = $callback;
}
diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php
index 12f1c43adde..d0dd794a77c 100644
--- a/tests/lib/BackgroundJob/TimedJobTest.php
+++ b/tests/lib/BackgroundJob/TimedJobTest.php
@@ -9,23 +9,10 @@
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
-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;
+class TestTimedJobNew extends TimedJob {
+ public bool $ran = false;
public function __construct(ITimeFactory $timeFactory) {
parent::__construct($timeFactory);
@@ -38,57 +25,23 @@ class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob {
}
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);
- }
-
- public function testShouldRunAfterInterval() {
- $job = new TestTimedJob();
- $this->jobList->add($job);
-
- $job->setLastRun(time() - 12);
- $job->execute($this->jobList);
- $this->assertTrue($job->ran);
+ $this->time = \OCP\Server::get(ITimeFactory::class);
}
- 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() {
$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);
}
@@ -98,7 +51,7 @@ class TimedJobTest extends \Test\TestCase {
$this->jobList->add($job);
$job->setLastRun(time() - 5);
- $job->execute($this->jobList);
+ $job->start($this->jobList);
$this->assertFalse($job->ran);
}
@@ -108,10 +61,10 @@ class TimedJobTest extends \Test\TestCase {
$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);
}
}