Skip to content

Commit

Permalink
OXDEV-7573 Handle select case
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 16, 2023
1 parent dd9cf84 commit 4f3a287
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
17 changes: 7 additions & 10 deletions src/Setting/Infrastructure/ShopSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,17 @@ public function getString(string $name): string
return (string)$setting->getValue();
}

protected function getShopSetting(string $name): ShopConfigurationSetting
public function getSelect(string $name): string
{
return $this->configurationSettingDao->get($name, $this->basicContext->getCurrentShopId());
$setting = $this->getShopSetting($name);
$this->checkSettingType($setting, FieldType::SELECT);

return (string)$setting->getValue();
}

public function getSelect(ID $name): string
protected function getShopSetting(string $name): ShopConfigurationSetting
{
try {
$value = $this->getSettingValue($name, FieldType::SELECT);
} catch (NotFound $e) {
$this->throwGetterNotFoundException('select');
}

return $value;
return $this->configurationSettingDao->get($name, $this->basicContext->getCurrentShopId());
}

public function getCollection(ID $name): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getBoolean(string $name): bool;

public function getString(string $name): string;

public function getSelect(ID $name): string;
public function getSelect(string $name): string;

public function getCollection(ID $name): array;

Expand Down
4 changes: 2 additions & 2 deletions src/Setting/Service/ShopSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function getStringSetting(string $name): StringSetting
return new StringSetting(new ID($name), $string);
}

public function getSelectSetting(ID $name): StringSetting
public function getSelectSetting(string $name): StringSetting
{
$select = $this->shopSettingRepository->getSelect($name);
return new StringSetting($name, $select);
return new StringSetting(new ID($name), $select);
}

public function getCollectionSetting(ID $name): StringSetting
Expand Down
2 changes: 1 addition & 1 deletion src/Setting/Service/ShopSettingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getBooleanSetting(string $name): BooleanSetting;

public function getStringSetting(string $name): StringSetting;

public function getSelectSetting(ID $name): StringSetting;
public function getSelectSetting(string $name): StringSetting;

public function getCollectionSetting(ID $name): StringSetting;

Expand Down
45 changes: 28 additions & 17 deletions tests/Unit/Infrastructure/ShopSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public function wrongSettingsDataProvider(): \Generator
'value' => 'any',
'expectedException' => WrongSettingTypeException::class
];

yield [
'method' => 'getSelect',
'type' => 'wrong',
'value' => 'any',
'expectedException' => WrongSettingTypeException::class
];
}

/** @dataProvider possibleBoolValuesDataProvider */
Expand Down Expand Up @@ -259,28 +266,32 @@ public function possibleStringValuesDataProvider(): \Generator
yield ['possibleValue' => '', 'expectedResult' => ''];
}


public function testGetShopSettingSelect(): void
/** @dataProvider possibleStringValuesDataProvider */
public function testGetShopSettingSelect($possibleValue, $expectedResult): void
{
$nameID = new ID('selectSetting');


$repository = $this->getFetchOneShopSettingRepoInstance('select');

$select = $repository->getSelect($nameID);
$settingName = 'settingName';
$shopId = 3;

$this->assertEquals('select', $select);
}
$shopSettingDaoStub = $this->createMock(ShopConfigurationSettingDaoInterface::class);
$shopSettingDaoStub->method('get')
->with($settingName, $shopId)
->willReturn(
$this->createConfiguredMock(ShopConfigurationSetting::class, [
'getName' => $settingName,
'getType' => FieldType::SELECT,
'getValue' => $possibleValue
])
);

public function testGetNoShopSettingSelect(): void
{
$nameID = new ID('NotExistingSetting');
$basicContext = $this->createStub(BasicContextInterface::class);
$basicContext->method('getCurrentShopId')->willReturn($shopId);

$repository = $this->getFetchOneShopSettingRepoInstance(false);
$sut = $this->getSut(
basicContext: $basicContext,
shopSettingDao: $shopSettingDaoStub
);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a select configuration');
$repository->getSelect($nameID);
$this->assertSame($expectedResult, $sut->getSelect($settingName));
}

public function testGetShopSettingCollection(): void
Expand Down

0 comments on commit 4f3a287

Please sign in to comment.