Skip to content

Commit 4026c0b

Browse files
committed
use ocp server get
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent e7fe984 commit 4026c0b

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

tests/unit/Providers/OpenAiProviderTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,31 @@ public static function setUpBeforeClass(): void {
5656
parent::setUpBeforeClass();
5757
$backend = new Dummy();
5858
$backend->createUser(self::TEST_USER1, self::TEST_USER1);
59-
\OC::$server->get(\OCP\IUserManager::class)->registerBackend($backend);
59+
\OCP\Server::get(\OCP\IUserManager::class)->registerBackend($backend);
6060
}
6161

6262
protected function setUp(): void {
6363
parent::setUp();
6464

6565
$this->loginAsUser(self::TEST_USER1);
6666

67-
$this->openAiSettingsService = \OC::$server->get(OpenAiSettingsService::class);
67+
$this->openAiSettingsService = \OCP\Server::get(OpenAiSettingsService::class);
6868

69-
$this->chunkService = \OC::$server->get(ChunkService::class);
69+
$this->chunkService = \OCP\Server::get(ChunkService::class);
7070

71-
$this->quotaUsageMapper = \OC::$server->get(QuotaUsageMapper::class);
71+
$this->quotaUsageMapper = \OCP\Server::get(QuotaUsageMapper::class);
7272

7373
// We'll hijack the client service and subsequently iClient to return a mock response from the OpenAI API
7474
$clientService = $this->createMock(IClientService::class);
7575
$this->iClient = $this->createMock(IClient::class);
7676
$clientService->method('newClient')->willReturn($this->iClient);
7777

7878
$this->openAiApiService = new OpenAiAPIService(
79-
\OC::$server->get(\Psr\Log\LoggerInterface::class),
79+
\OCP\Server::get(\Psr\Log\LoggerInterface::class),
8080
$this->createMock(\OCP\IL10N::class),
81-
\OC::$server->get(IAppConfig::class),
82-
\OC::$server->get(ICacheFactory::class),
83-
\OC::$server->get(QuotaUsageMapper::class),
81+
\OCP\Server::get(IAppConfig::class),
82+
\OCP\Server::get(ICacheFactory::class),
83+
\OCP\Server::get(QuotaUsageMapper::class),
8484
$this->openAiSettingsService,
8585
$this->createMock(\OCP\Notification\IManager::class),
8686
$clientService,
@@ -91,7 +91,7 @@ protected function setUp(): void {
9191

9292
public static function tearDownAfterClass(): void {
9393
// Delete quota usage for test user
94-
$quotaUsageMapper = \OC::$server->get(QuotaUsageMapper::class);
94+
$quotaUsageMapper = \OCP\Server::get(QuotaUsageMapper::class);
9595
try {
9696
$quotaUsageMapper->deleteUserQuotaUsages(self::TEST_USER1);
9797
} catch (\OCP\Db\Exception|\RuntimeException|\Exception|\Throwable $e) {
@@ -100,15 +100,15 @@ public static function tearDownAfterClass(): void {
100100

101101
$backend = new \Test\Util\User\Dummy();
102102
$backend->deleteUser(self::TEST_USER1);
103-
\OC::$server->get(\OCP\IUserManager::class)->removeBackend($backend);
103+
\OCP\Server::get(\OCP\IUserManager::class)->removeBackend($backend);
104104

105105
parent::tearDownAfterClass();
106106
}
107107

108108
public function testFreePromptProvider(): void {
109109
$freePromptProvider = new TextToTextProvider(
110110
$this->openAiApiService,
111-
\OC::$server->get(IAppConfig::class),
111+
\OCP\Server::get(IAppConfig::class),
112112
$this->openAiSettingsService,
113113
$this->createMock(\OCP\IL10N::class),
114114
self::TEST_USER1,
@@ -171,7 +171,7 @@ public function testFreePromptProvider(): void {
171171
public function testEmojiProvider(): void {
172172
$emojiProvider = new EmojiProvider(
173173
$this->openAiApiService,
174-
\OC::$server->get(IAppConfig::class),
174+
\OCP\Server::get(IAppConfig::class),
175175
$this->openAiSettingsService,
176176
$this->createMock(\OCP\IL10N::class),
177177
self::TEST_USER1,
@@ -236,7 +236,7 @@ public function testEmojiProvider(): void {
236236
public function testHeadlineProvider(): void {
237237
$headlineProvider = new HeadlineProvider(
238238
$this->openAiApiService,
239-
\OC::$server->get(IAppConfig::class),
239+
\OCP\Server::get(IAppConfig::class),
240240
$this->openAiSettingsService,
241241
$this->createMock(\OCP\IL10N::class),
242242
self::TEST_USER1,
@@ -300,7 +300,7 @@ public function testHeadlineProvider(): void {
300300
public function testChangeToneProvider(): void {
301301
$changeToneProvider = new ChangeToneProvider(
302302
$this->openAiApiService,
303-
\OC::$server->get(IAppConfig::class),
303+
\OCP\Server::get(IAppConfig::class),
304304
$this->openAiSettingsService,
305305
$this->createMock(\OCP\IL10N::class),
306306
$this->chunkService,
@@ -367,7 +367,7 @@ public function testChangeToneProvider(): void {
367367
public function testSummaryProvider(): void {
368368
$summaryProvider = new SummaryProvider(
369369
$this->openAiApiService,
370-
\OC::$server->get(IAppConfig::class),
370+
\OCP\Server::get(IAppConfig::class),
371371
$this->openAiSettingsService,
372372
$this->createMock(\OCP\IL10N::class),
373373
$this->chunkService,
@@ -436,7 +436,7 @@ public function testSummaryProvider(): void {
436436
public function testProofreadProvider(): void {
437437
$proofreadProvider = new ProofreadProvider(
438438
$this->openAiApiService,
439-
\OC::$server->get(IAppConfig::class),
439+
\OCP\Server::get(IAppConfig::class),
440440
$this->openAiSettingsService,
441441
$this->createMock(\OCP\IL10N::class),
442442
$this->chunkService,
@@ -504,10 +504,10 @@ public function testProofreadProvider(): void {
504504
public function testTranslationProvider(): void {
505505
$translationProvider = new TranslateProvider(
506506
$this->openAiApiService,
507-
\OC::$server->get(IAppConfig::class),
507+
\OCP\Server::get(IAppConfig::class),
508508
$this->openAiSettingsService,
509509
$this->createMock(\OCP\IL10N::class),
510-
\OC::$server->get(\OCP\L10N\IFactory::class),
510+
\OCP\Server::get(\OCP\L10N\IFactory::class),
511511
$this->createMock(\OCP\ICacheFactory::class),
512512
$this->createMock(\Psr\Log\LoggerInterface::class),
513513
$this->chunkService,
@@ -577,7 +577,7 @@ public function testTextToSpeechProvider(): void {
577577
$this->openAiApiService,
578578
$this->createMock(\OCP\IL10N::class),
579579
$this->createMock(\Psr\Log\LoggerInterface::class),
580-
\OC::$server->get(IAppConfig::class),
580+
\OCP\Server::get(IAppConfig::class),
581581
self::TEST_USER1,
582582
);
583583

tests/unit/Quota/QuotaTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace OCA\OpenAi\Tests\Unit\Quota;
1414

1515
use Exception;
16-
use OC;
1716
use OCA\OpenAi\AppInfo\Application;
1817
use OCA\OpenAi\Db\QuotaUsageMapper;
1918
use OCA\OpenAi\Service\OpenAiAPIService;
@@ -55,38 +54,38 @@ public static function setUpBeforeClass(): void {
5554
parent::setUpBeforeClass();
5655
$backend = new Dummy();
5756
$backend->createUser(self::TEST_USER1, self::TEST_USER1);
58-
OC::$server->get(IUserManager::class)->registerBackend($backend);
57+
\OCP\Server::get(IUserManager::class)->registerBackend($backend);
5958
}
6059

6160
protected function setUp(): void {
6261
parent::setUp();
6362

6463
$this->loginAsUser(self::TEST_USER1);
6564

66-
$this->openAiSettingsService = OC::$server->get(OpenAiSettingsService::class);
65+
$this->openAiSettingsService = \OCP\Server::get(OpenAiSettingsService::class);
6766

68-
$this->quotaUsageMapper = OC::$server->get(QuotaUsageMapper::class);
67+
$this->quotaUsageMapper = \OCP\Server::get(QuotaUsageMapper::class);
6968

7069
$this->notificationManager = $this->createMock(IManager::class);
7170

7271
$this->cacheFactory = $this->createMock(ICacheFactory::class);
7372

7473

7574
$this->openAiApiService = new OpenAiAPIService(
76-
OC::$server->get(LoggerInterface::class),
75+
\OCP\Server::get(LoggerInterface::class),
7776
$this->createMock(IL10N::class),
78-
OC::$server->get(IAppConfig::class),
77+
\OCP\Server::get(IAppConfig::class),
7978
$this->cacheFactory,
80-
OC::$server->get(QuotaUsageMapper::class),
79+
\OCP\Server::get(QuotaUsageMapper::class),
8180
$this->openAiSettingsService,
8281
$this->notificationManager,
83-
OC::$server->get(IClientService::class),
82+
\OCP\Server::get(IClientService::class),
8483
);
8584
}
8685

8786
public static function tearDownAfterClass(): void {
8887
// Delete quota usage for test user
89-
$quotaUsageMapper = OC::$server->get(QuotaUsageMapper::class);
88+
$quotaUsageMapper = \OCP\Server::get(QuotaUsageMapper::class);
9089
try {
9190
$quotaUsageMapper->deleteUserQuotaUsages(self::TEST_USER1);
9291
} catch (\OCP\Db\Exception|RuntimeException|Exception|Throwable $e) {
@@ -95,7 +94,7 @@ public static function tearDownAfterClass(): void {
9594

9695
$backend = new Dummy();
9796
$backend->deleteUser(self::TEST_USER1);
98-
OC::$server->get(IUserManager::class)->removeBackend($backend);
97+
\OCP\Server::get(IUserManager::class)->removeBackend($backend);
9998

10099
parent::tearDownAfterClass();
101100
}

0 commit comments

Comments
 (0)