From 48d9c4d2b093e12ec3bf3cd29295da0f2277028f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 28 Jun 2022 12:55:26 +0200 Subject: Port existing server code to new interface Signed-off-by: Carl Schwan --- tests/lib/BackgroundJob/DummyJobList.php | 2 +- tests/lib/Migration/BackgroundRepairTest.php | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index be9c06257b7..4d14ed9e7db 100644 --- a/tests/lib/BackgroundJob/DummyJobList.php +++ b/tests/lib/BackgroundJob/DummyJobList.php @@ -33,7 +33,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { public function add($job, $argument = null): void { if (is_string($job)) { /** @var IJob $job */ - $job = new $job; + $job = \OCP\Server::get($job); } $job->setArgument($argument); if (!$this->has($job, null)) { diff --git a/tests/lib/Migration/BackgroundRepairTest.php b/tests/lib/Migration/BackgroundRepairTest.php index 4e95915e624..7da9b18de30 100644 --- a/tests/lib/Migration/BackgroundRepairTest.php +++ b/tests/lib/Migration/BackgroundRepairTest.php @@ -23,12 +23,13 @@ namespace Test\Migration; use OC\Migration\BackgroundRepair; use OC\NeedsUpdateException; -use OCP\ILogger; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; +use Psr\Log\LoggerInterface; class TestRepairStep implements IRepairStep { @@ -62,31 +63,37 @@ class BackgroundRepairTest extends TestCase { /** @var BackgroundRepair|\PHPUnit\Framework\MockObject\MockObject */ private $job; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject $dispatcher */ private $dispatcher; + /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $dispatcher */ + private $time; + protected function setUp(): void { parent::setUp(); $this->jobList = $this->getMockBuilder('OC\BackgroundJob\JobList') ->disableOriginalConstructor() ->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class) + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->time = $this->createMock(ITimeFactory::class); + $this->time->method('getTime') + ->willReturn(999999); $this->job = $this->getMockBuilder(BackgroundRepair::class) - ->setConstructorArgs([$this->dispatcher]) + ->setConstructorArgs([$this->dispatcher, $this->time, $this->logger, $this->jobList]) ->setMethods(['loadApp']) ->getMock(); } public function testNoArguments() { $this->jobList->expects($this->once())->method('remove'); - $this->job->execute($this->jobList); + $this->job->start($this->jobList); } public function testAppUpgrading() { @@ -96,20 +103,20 @@ class BackgroundRepairTest extends TestCase { 'app' => 'test', 'step' => 'j' ]); - $this->job->execute($this->jobList); + $this->job->start($this->jobList); } public function testUnknownStep() { $this->dispatcher->expects($this->never())->method('dispatch'); $this->jobList->expects($this->once())->method('remove'); - $this->logger->expects($this->once())->method('logException'); + $this->logger->expects($this->once())->method('error'); $this->job->setArgument([ 'app' => 'test', 'step' => 'j' ]); - $this->job->execute($this->jobList, $this->logger); + $this->job->start($this->jobList); } public function testWorkingStep() { @@ -122,6 +129,6 @@ class BackgroundRepairTest extends TestCase { 'app' => 'test', 'step' => '\Test\Migration\TestRepairStep' ]); - $this->job->execute($this->jobList, $this->logger); + $this->job->start($this->jobList); } } -- cgit v1.2.3