Skip to content

Commit

Permalink
OXDEV-7458 Implement the saveIntegerSetting in repository
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 17, 2023
1 parent c9d16e0 commit ed8af24
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Setting/Infrastructure/ShopSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/Setting/Infrastructure/ShopSettingRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public function getAssocCollection(string $name): array;
* @return array<string, string>
*/
public function getSettingsList(): array;

public function saveIntegerSetting(string $name, int $value): void;
}
48 changes: 46 additions & 2 deletions tests/Unit/Infrastructure/ShopSettingRepositorySettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ed8af24

Please sign in to comment.