diff options
Diffstat (limited to 'tests/lib/BackgroundJob')
-rw-r--r-- | tests/lib/BackgroundJob/DummyJobList.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/JobTest.php | 22 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/QueuedJobTest.php | 34 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/TestJob.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/TimedJobTest.php | 67 |
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); } } |