diff options
Diffstat (limited to 'tests/lib/TextProcessing/TextProcessingTest.php')
-rw-r--r-- | tests/lib/TextProcessing/TextProcessingTest.php | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/tests/lib/TextProcessing/TextProcessingTest.php b/tests/lib/TextProcessing/TextProcessingTest.php index db479a7a7b6..bdcb4a57d7c 100644 --- a/tests/lib/TextProcessing/TextProcessingTest.php +++ b/tests/lib/TextProcessing/TextProcessingTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -23,6 +24,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IServerContainer; use OCP\PreConditionNotMetException; +use OCP\Server; use OCP\TextProcessing\Events\TaskFailedEvent; use OCP\TextProcessing\Events\TaskSuccessfulEvent; use OCP\TextProcessing\FreePromptTaskType; @@ -86,6 +88,9 @@ class FreePromptProvider implements IProvider { } } +/** + * @group DB + */ class TextProcessingTest extends \Test\TestCase { private IManager $manager; private Coordinator $coordinator; @@ -115,7 +120,7 @@ class TextProcessingTest extends \Test\TestCase { $this->eventDispatcher = new EventDispatcher( new \Symfony\Component\EventDispatcher\EventDispatcher(), $this->serverContainer, - \OC::$server->get(LoggerInterface::class), + Server::get(LoggerInterface::class), ); $this->registrationContext = $this->createMock(RegistrationContext::class); @@ -155,14 +160,14 @@ class TextProcessingTest extends \Test\TestCase { $this->taskMapper ->expects($this->any()) ->method('deleteOlderThan') - ->willReturnCallback(function (int $timeout) { + ->willReturnCallback(function (int $timeout): void { $this->tasksDb = array_filter($this->tasksDb, function (array $task) use ($timeout) { return $task['last_updated'] >= $this->currentTime->getTimestamp() - $timeout; }); }); $this->jobList = $this->createPartialMock(DummyJobList::class, ['add']); - $this->jobList->expects($this->any())->method('add')->willReturnCallback(function () { + $this->jobList->expects($this->any())->method('add')->willReturnCallback(function (): void { }); $config = $this->createMock(IConfig::class); @@ -173,14 +178,15 @@ class TextProcessingTest extends \Test\TestCase { $this->manager = new Manager( $this->serverContainer, $this->coordinator, - \OC::$server->get(LoggerInterface::class), + Server::get(LoggerInterface::class), $this->jobList, $this->taskMapper, - $config + $config, + $this->createMock(\OCP\TaskProcessing\IManager::class), ); } - public function testShouldNotHaveAnyProviders() { + public function testShouldNotHaveAnyProviders(): void { $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([]); $this->assertCount(0, $this->manager->getAvailableTaskTypes()); $this->assertFalse($this->manager->hasProviders()); @@ -188,7 +194,7 @@ class TextProcessingTest extends \Test\TestCase { $this->manager->runTask(new \OCP\TextProcessing\Task(FreePromptTaskType::class, 'Hello', 'test', null)); } - public function testProviderShouldBeRegisteredAndRun() { + public function testProviderShouldBeRegisteredAndRun(): void { $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([ new ServiceRegistration('test', SuccessfulSummaryProvider::class) ]); @@ -201,7 +207,7 @@ class TextProcessingTest extends \Test\TestCase { $this->manager->runTask(new Task(FreePromptTaskType::class, 'Hello', 'test', null)); } - public function testProviderShouldBeRegisteredAndScheduled() { + public function testProviderShouldBeRegisteredAndScheduled(): void { // register provider $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([ new ServiceRegistration('test', SuccessfulSummaryProvider::class) @@ -235,7 +241,7 @@ class TextProcessingTest extends \Test\TestCase { // run background job $bgJob = new TaskBackgroundJob( - \OC::$server->get(ITimeFactory::class), + Server::get(ITimeFactory::class), $this->manager, $this->eventDispatcher, ); @@ -252,7 +258,7 @@ class TextProcessingTest extends \Test\TestCase { $this->assertEquals(Task::STATUS_SUCCESSFUL, $task3->getStatus()); } - public function testMultipleProvidersShouldBeRegisteredAndRunCorrectly() { + public function testMultipleProvidersShouldBeRegisteredAndRunCorrectly(): void { $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([ new ServiceRegistration('test', SuccessfulSummaryProvider::class), new ServiceRegistration('test', FreePromptProvider::class), @@ -271,12 +277,12 @@ class TextProcessingTest extends \Test\TestCase { $this->manager->runTask(new Task(TopicsTaskType::class, 'Hello', 'test', null)); } - public function testNonexistentTask() { + public function testNonexistentTask(): void { $this->expectException(NotFoundException::class); $this->manager->getTask(2147483646); } - public function testTaskFailure() { + public function testTaskFailure(): void { // register provider $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([ new ServiceRegistration('test', FailingSummaryProvider::class), @@ -310,7 +316,7 @@ class TextProcessingTest extends \Test\TestCase { // run background job $bgJob = new TaskBackgroundJob( - \OC::$server->get(ITimeFactory::class), + Server::get(ITimeFactory::class), $this->manager, $this->eventDispatcher, ); @@ -327,7 +333,7 @@ class TextProcessingTest extends \Test\TestCase { $this->assertEquals(Task::STATUS_FAILED, $task3->getStatus()); } - public function testOldTasksShouldBeCleanedUp() { + public function testOldTasksShouldBeCleanedUp(): void { $this->registrationContext->expects($this->any())->method('getTextProcessingProviders')->willReturn([ new ServiceRegistration('test', SuccessfulSummaryProvider::class) ]); @@ -339,9 +345,9 @@ class TextProcessingTest extends \Test\TestCase { $this->currentTime = $this->currentTime->add(new \DateInterval('P1Y')); // run background job $bgJob = new RemoveOldTasksBackgroundJob( - \OC::$server->get(ITimeFactory::class), + Server::get(ITimeFactory::class), $this->taskMapper, - \OC::$server->get(LoggerInterface::class), + Server::get(LoggerInterface::class), ); $bgJob->setArgument([]); $bgJob->start($this->jobList); |