-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-8215 Decoupled LanguageService from core language class
- Loading branch information
1 parent
b615494
commit deab496
Showing
7 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Shared\Core; | ||
|
||
use OxidEsales\Eshop\Core\Language; | ||
|
||
class LanguageWrapper implements LanguageWrapperInterface | ||
{ | ||
public function __construct( | ||
private Language $language | ||
) { | ||
} | ||
|
||
public function getBaseLanguage(): int | ||
{ | ||
/** @var int|null $langId */ | ||
$langId = $this->language->getBaseLanguage(); | ||
return (int)$langId; | ||
} | ||
|
||
public function getLanguageAbbr(?int $langId = null): string | ||
{ | ||
return $this->language->getLanguageAbbr(iLanguage: $langId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Shared\Core; | ||
|
||
interface LanguageWrapperInterface | ||
{ | ||
public function getBaseLanguage(): int; | ||
public function getLanguageAbbr(?int $langId = null): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
_defaults: | ||
public: false | ||
autowire: true | ||
bind: | ||
OxidEsales\Eshop\Core\Language: '@=service("OxidEsales\\GraphQL\\ConfigurationAccess\\Shared\\Core\\Registry").getLang()' | ||
|
||
OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\Registry: | ||
class: OxidEsales\Eshop\Core\Registry | ||
public: true | ||
|
||
OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\LanguageWrapperInterface: | ||
class: OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\LanguageWrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Shared\Core; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\LanguageWrapper; | ||
use PHPUnit\Framework\TestCase; | ||
use OxidEsales\Eshop\Core\Language; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\Core\LanguageWrapper; | ||
*/ | ||
class LanguageWrapperTest extends TestCase | ||
{ | ||
public function testGetBaseLanguage(): void | ||
{ | ||
$expectedLangId = 1; | ||
$languageMock = $this->createPartialMock(Language::class, ['getBaseLanguage']); | ||
$languageMock->method('getBaseLanguage')->willReturn($expectedLangId); | ||
|
||
$languageWrapper = new LanguageWrapper($languageMock); | ||
$actualLangId = $languageWrapper->getBaseLanguage(); | ||
|
||
$this->assertSame($expectedLangId, $actualLangId); | ||
} | ||
|
||
public function testGetLanguageAbbr(): void | ||
{ | ||
$langId = 1; | ||
$expectedLangAbbr = uniqid(); | ||
$languageMock = $this->createPartialMock(Language::class, ['getLanguageAbbr']); | ||
$languageMock->method('getLanguageAbbr')->willReturn($expectedLangAbbr); | ||
|
||
$languageWrapper = new LanguageWrapper($languageMock); | ||
$actualLangAbbr = $languageWrapper->getLanguageAbbr($langId); | ||
|
||
$this->assertSame($expectedLangAbbr, $actualLangAbbr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters