From ed8af24dfca7c37bc62ee9ae3dd10a6a1eb95f78 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 17 Nov 2023 16:15:39 +0200 Subject: [PATCH] OXDEV-7458 Implement the saveIntegerSetting in repository Signed-off-by: Anton Fedurtsya --- .../Infrastructure/ShopSettingRepository.php | 11 +++++ .../ShopSettingRepositoryInterface.php | 2 + .../ShopSettingRepositorySettersTest.php | 48 ++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Setting/Infrastructure/ShopSettingRepository.php b/src/Setting/Infrastructure/ShopSettingRepository.php index ebdc902..555ca8a 100644 --- a/src/Setting/Infrastructure/ShopSettingRepository.php +++ b/src/Setting/Infrastructure/ShopSettingRepository.php @@ -173,4 +173,15 @@ public function getArrayFromSettingValue(ShopConfigurationSetting $setting): arr return $value; } + + public function saveIntegerSetting(string $name, int $value): void + { + $setting = (new ShopConfigurationSetting()) + ->setShopId($this->basicContext->getCurrentShopId()) + ->setName($name) + ->setType(FieldType::NUMBER) + ->setValue($value); + + $this->configurationSettingDao->save($setting); + } } diff --git a/src/Setting/Infrastructure/ShopSettingRepositoryInterface.php b/src/Setting/Infrastructure/ShopSettingRepositoryInterface.php index b73d7a5..65a3652 100644 --- a/src/Setting/Infrastructure/ShopSettingRepositoryInterface.php +++ b/src/Setting/Infrastructure/ShopSettingRepositoryInterface.php @@ -25,4 +25,6 @@ public function getAssocCollection(string $name): array; * @return array */ public function getSettingsList(): array; + + public function saveIntegerSetting(string $name, int $value): void; } diff --git a/tests/Unit/Infrastructure/ShopSettingRepositorySettersTest.php b/tests/Unit/Infrastructure/ShopSettingRepositorySettersTest.php index 8043273..b4ec90b 100644 --- a/tests/Unit/Infrastructure/ShopSettingRepositorySettersTest.php +++ b/tests/Unit/Infrastructure/ShopSettingRepositorySettersTest.php @@ -2,13 +2,57 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Infrastructure; +use OxidEsales\EshopCommunity\Internal\Framework\Config\Dao\ShopConfigurationSettingDaoInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Config\DataObject\ShopConfigurationSetting; +use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface; +use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType; + /** * @covers \OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ShopSettingRepository */ class ShopSettingRepositorySettersTest extends AbstractShopSettingRepositoryTest { - public function testSetShopSetting(): void + /** @dataProvider shopSettingsSaveMethodsDataProvider */ + public function testSetShopSetting(string $method, $settingValue, string $settingType): void { -// $this->assertTrue(false); + $shopId = 3; + $settingName = 'settingName'; + + $setting = $this->buildShopSettingStub($shopId, $settingType, $settingName, $settingValue); + + $basicContextStub = $this->createStub(BasicContextInterface::class); + $basicContextStub->method('getCurrentShopId')->willReturn($shopId); + + $shopSettingDaoSpy = $this->createMock(ShopConfigurationSettingDaoInterface::class); + $shopSettingDaoSpy->expects($this->once())->method('save')->with($this->equalTo($setting)); + + $sut = $this->getSut( + basicContext: $basicContextStub, + shopSettingDao: $shopSettingDaoSpy + ); + + $sut->$method($settingName, $settingValue); + } + + public function shopSettingsSaveMethodsDataProvider(): \Generator + { + yield 'integer' => [ + 'method' => 'saveIntegerSetting', + 'settingValue' => 123, + 'settingType' => FieldType::NUMBER + ]; + } + + public function buildShopSettingStub( + int $shopId, + string $settingType, + string $settingName, + int $settingValue + ): ShopConfigurationSetting { + return (new ShopConfigurationSetting()) + ->setShopId($shopId) + ->setName($settingName) + ->setType($settingType) + ->setValue($settingValue); } }