Skip to content

Commit

Permalink
OXDEV-7557 Refactor the getSettingList test to check if setting gette…
Browse files Browse the repository at this point in the history
…r is called correctly

Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 15, 2023
1 parent be1f1f1 commit 421da94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/Setting/Infrastructure/ModuleSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use TheCodingMachine\GraphQLite\Types\ID;

final class ModuleSettingRepository implements ModuleSettingRepositoryInterface
{
Expand Down
40 changes: 24 additions & 16 deletions tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ModuleSettingRepository;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\UnitTestCase;
use Symfony\Component\String\UnicodeString;
use TheCodingMachine\GraphQLite\Types\ID;

class ModuleSettingRepositoryTest extends UnitTestCase
{
Expand Down Expand Up @@ -213,25 +210,36 @@ public function testSaveCollectionSettingProxyingDataToShopService(): void

public function testGetSettingsList(): void
{
$intSetting = (new Setting())->setName('intSetting')->setType(FieldType::NUMBER);
$stringSetting = (new Setting())->setName('stringSetting')->setType(FieldType::STRING);
$arraySetting = (new Setting())->setName('arraySetting')->setType(FieldType::ARRAY);

$moduleConfiguration = $this->createMock(ModuleConfiguration::class);
$moduleConfiguration->expects($this->once())
->method('getModuleSettings')
->willReturn([$intSetting, $stringSetting, $arraySetting]);
$shopId = 3;
$moduleId = 'awesomeModule';

$response = [
$this->createStub(Setting::class),
$this->createStub(Setting::class),
];

$moduleConfigurationDao = $this->createMock(ModuleConfigurationDaoInterface::class);
$moduleConfigurationDao->expects($this->once())
->method('get')
->willReturn($moduleConfiguration);
->with($moduleId, $shopId)
->willReturn(
$this->createConfiguredMock(ModuleConfiguration::class, [
'getModuleSettings' => $response
])
);

$basicContext = $this->createMock(BasicContextInterface::class);
$basicContext->method('getCurrentShopId')->willReturn($shopId);

$moduleRepository = $this->getSut(
$this->createMock(ModuleSettingServiceInterface::class),
$moduleConfigurationDao
moduleConfigurationDao: $moduleConfigurationDao,
basicContext: $basicContext,
);

$this->assertSame(
$response,
$moduleRepository->getSettingsList($moduleId)
);
$settingsList = $moduleRepository->getSettingsList('awesomeModule');
$this->assertEquals([$intSetting, $stringSetting, $arraySetting], $settingsList);
}

public function getSut(
Expand Down

0 comments on commit 421da94

Please sign in to comment.