Skip to content

Commit

Permalink
Adapt to latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gradinarufelix committed Jan 17, 2024
1 parent 19e06f6 commit 87d6715
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
use Neos\Flow\Tests\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Sitegeist\LostInTranslation\Infrastructure\DeepL\DeepLAuthenticationKeyFactory;
use Sitegeist\LostInTranslation\Infrastructure\DeepL\DeepLCustomAuthenticationKeyService;

class DeepLAuthenticationKeyFactoryTest extends UnitTestCase
{
protected MockObject|StringFrontend $apiKeyCache;
protected MockObject|DeepLCustomAuthenticationKeyService $customKeyService;
public function setUp(): void
{
$this->apiKeyCache = $this->getAccessibleMock(StringFrontend::class, ['get'], [], '', false);
$this->customKeyService = $this->getAccessibleMock(DeepLCustomAuthenticationKeyService::class, ['get'], [], '', false);
}

/** @test */
public function cachedCustomKeyOverridesConfiguredAuthenticationKey(): void
{
$this->apiKeyCache->method('get')->willReturn('cachedKey');
$this->customKeyService->method('get')->willReturn('cachedKey');


$authenticationKey = $this->getFactory()->create();
Expand All @@ -30,7 +31,7 @@ public function cachedCustomKeyOverridesConfiguredAuthenticationKey(): void
/** @test */
public function canBeCreatedWithConfiguredAuthenticationKey(): void
{
$this->apiKeyCache->method('get')->willReturn(false);
$this->customKeyService->method('get')->willReturn(null);


$authenticationKey = $this->getFactory()->create();
Expand All @@ -42,7 +43,7 @@ public function canBeCreatedWithConfiguredAuthenticationKey(): void
protected function getFactory(): MockObject|DeepLAuthenticationKeyFactory
{
$factory = new DeepLAuthenticationKeyFactory();
$this->inject($factory, 'apiKeyCache', $this->apiKeyCache);
$this->inject($factory, 'customAuthenticationKeyService', $this->customKeyService);
$this->inject($factory, 'settings', [
'authenticationKey' => 'configuredKey'
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function canBeConstructedCorrectly(string $authenticationKey, string $exp
$authenticationKeyObject = new DeepLAuthenticationKey($authenticationKey);


$this->assertEquals($expectedIsFree, $authenticationKeyObject->isFree());
$this->assertEquals($expectedAuthenticationKey, $authenticationKeyObject->getAuthenticationKey());
$this->assertEquals($authenticationKey, $authenticationKeyObject->__toString());
$this->assertEquals($expectedIsFree, $authenticationKeyObject->isFree);
$this->assertEquals($expectedAuthenticationKey, $authenticationKeyObject->authenticationKey);
$this->assertEquals($authenticationKey, (string)$authenticationKeyObject);
}
}
10 changes: 5 additions & 5 deletions Tests/Unit/Infrastructure/DeepL/DeepLTranslationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Sitegeist\LostInTranslation\Infrastructure\DeepL\DeepLAuthenticationKey;
use Sitegeist\LostInTranslation\Infrastructure\DeepL\DeepLCustomAuthenticationKeyService;
use Sitegeist\LostInTranslation\Infrastructure\DeepL\DeepLTranslationService;

class DeepLTranslationServiceTest extends UnitTestCase
{
protected MockObject|VariableFrontend $translationCache;
protected MockObject|VariableFrontend $apiKeyCache;
protected MockObject|DeepLCustomAuthenticationKeyService $customKeyServiceMock;
protected MockObject|LoggerInterface $loggerMock;
protected MockObject|Browser $browserMock;

public function setUp(): void
{
$this->translationCache = new VariableFrontend('Sitegeist_LostInTranslation_TranslationCache', new TransientMemoryBackend());
$this->translationCache->initializeObject();
$this->apiKeyCache = $this->getAccessibleMock(StringFrontend::class, ['get', 'has'], [], '', false);
$this->customKeyServiceMock = $this->getAccessibleMock(DeepLCustomAuthenticationKeyService::class, ['get'], [], '', false);
$this->loggerMock = Mockery::mock(LoggerInterface::class);
$this->browserMock = $this->getAccessibleMock(Browser::class, ['sendRequest'], [], '', false);
}
Expand Down Expand Up @@ -200,8 +201,7 @@ public static function getApiStatusWorksCorrectlyData(): array
public function getApiStatusWorksCorrectly(string|null $settingsKey, string|bool $customKey, Response $usageResponse, int $expectedCharacterCount, int $expectedCharacterLimit, bool $expectedHasSettingsKey, bool $expectedHasCustomKey, bool $expectedIsFree): void
{
$service = $this->getService(['authenticationKey' => $settingsKey]);
$this->apiKeyCache->method('has')->willReturn($customKey !== false);
$this->apiKeyCache->method('get')->willReturn($customKey);
$this->customKeyServiceMock->method('get')->willReturn($customKey);
$this->browserMock->method('sendRequest')->willReturn($usageResponse);
$validAuthenticationKey = ($customKey ?: null) ?? $settingsKey ?? null;
if ($validAuthenticationKey) {
Expand All @@ -228,7 +228,7 @@ public function getService(array $overrideSettings = []): MockObject|DeepLTransl
$this->inject($service, 'streamFactory', new StreamFactory());
$this->inject($service, 'logger', $this->loggerMock);
$this->inject($service, 'translationCache', $this->translationCache);
$this->inject($service, 'apiKeyCache', $this->apiKeyCache);
$this->inject($service, 'customAuthenticationKeyService', $this->customKeyServiceMock);
$this->inject($service, 'settings', array_merge_recursive([
'baseUri' => 'https://api.deepl.com/v2/',
'baseUriFree' => 'https://api-free.deepl.com/v2/',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"config": {
"bin-dir": "bin",
"vendor-dir": "Packages/Libraries",
"allow-plugins": {
"neos/composer-plugin": true
}
Expand Down

0 comments on commit 87d6715

Please sign in to comment.