Skip to content

Commit

Permalink
OXDEV-7557 Remove usage of ID in ModuleSettingRepository setters
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 15, 2023
1 parent a6021a2 commit be1f1f1
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 92 deletions.
20 changes: 10 additions & 10 deletions src/Setting/Infrastructure/ModuleSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ public function getCollectionSetting(string $name, string $moduleId): array
return $this->moduleSettingService->getCollection($name, $moduleId);
}

public function saveIntegerSetting(ID $name, int $value, string $moduleId): void
public function saveIntegerSetting(string $name, int $value, string $moduleId): void
{
$this->moduleSettingService->saveInteger($name->val(), $value, $moduleId);
$this->moduleSettingService->saveInteger($name, $value, $moduleId);
}

public function saveFloatSetting(ID $name, float $value, string $moduleId): void
public function saveFloatSetting(string $name, float $value, string $moduleId): void
{
$this->moduleSettingService->saveFloat($name->val(), $value, $moduleId);
$this->moduleSettingService->saveFloat($name, $value, $moduleId);
}

public function saveBooleanSetting(ID $name, bool $value, string $moduleId): void
public function saveBooleanSetting(string $name, bool $value, string $moduleId): void
{
$this->moduleSettingService->saveBoolean($name->val(), $value, $moduleId);
$this->moduleSettingService->saveBoolean($name, $value, $moduleId);
}

public function saveStringSetting(ID $name, string $value, string $moduleId): void
public function saveStringSetting(string $name, string $value, string $moduleId): void
{
$this->moduleSettingService->saveString($name->val(), $value, $moduleId);
$this->moduleSettingService->saveString($name, $value, $moduleId);
}

public function saveCollectionSetting(ID $name, array $value, string $moduleId): void
public function saveCollectionSetting(string $name, array $value, string $moduleId): void
{
$this->moduleSettingService->saveCollection($name->val(), $value, $moduleId);
$this->moduleSettingService->saveCollection($name, $value, $moduleId);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public function getStringSetting(string $name, string $moduleId): string;

public function getCollectionSetting(string $name, string $moduleId): array;

public function saveIntegerSetting(ID $name, int $value, string $moduleId): void;
public function saveIntegerSetting(string $name, int $value, string $moduleId): void;

public function saveFloatSetting(ID $name, float $value, string $moduleId): void;
public function saveFloatSetting(string $name, float $value, string $moduleId): void;

public function saveBooleanSetting(ID $name, bool $value, string $moduleId): void;
public function saveBooleanSetting(string $name, bool $value, string $moduleId): void;

public function saveStringSetting(ID $name, string $value, string $moduleId): void;
public function saveStringSetting(string $name, string $value, string $moduleId): void;

public function saveCollectionSetting(ID $name, array $value, string $moduleId): void;
public function saveCollectionSetting(string $name, array $value, string $moduleId): void;

/**
* @return Setting[]
Expand Down
20 changes: 10 additions & 10 deletions src/Setting/Service/ModuleSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,30 @@ public function getCollectionSetting(ID $name, string $moduleId): StringSetting

public function changeIntegerSetting(ID $name, int $value, string $moduleId): IntegerSetting
{
$this->moduleSettingRepository->saveIntegerSetting($name, $value, $moduleId);
$this->moduleSettingRepository->saveIntegerSetting((string)$name, $value, $moduleId);

return new IntegerSetting($name, $value);
return $this->getIntegerSetting($name, $moduleId);
}

public function changeFloatSetting(ID $name, float $value, string $moduleId): FloatSetting
{
$this->moduleSettingRepository->saveFloatSetting($name, $value, $moduleId);
$this->moduleSettingRepository->saveFloatSetting((string)$name, $value, $moduleId);

return new FloatSetting($name, $value);
return $this->getFloatSetting($name, $moduleId);
}

public function changeBooleanSetting(ID $name, bool $value, string $moduleId): BooleanSetting
{
$this->moduleSettingRepository->saveBooleanSetting($name, $value, $moduleId);
$this->moduleSettingRepository->saveBooleanSetting((string)$name, $value, $moduleId);

return new BooleanSetting($name, $value);
return $this->getBooleanSetting($name, $moduleId);
}

public function changeStringSetting(ID $name, string $value, string $moduleId): StringSetting
{
$this->moduleSettingRepository->saveStringSetting($name, $value, $moduleId);
$this->moduleSettingRepository->saveStringSetting((string)$name, $value, $moduleId);

return new StringSetting($name, $value);
return $this->getStringSetting($name, $moduleId);
}

public function changeCollectionSetting(ID $name, string $value, string $moduleId): StringSetting
Expand All @@ -105,9 +105,9 @@ public function changeCollectionSetting(ID $name, string $value, string $moduleI
throw new InvalidCollection($value);
}

$this->moduleSettingRepository->saveCollectionSetting($name, $arrayValue, $moduleId);
$this->moduleSettingRepository->saveCollectionSetting((string)$name, $arrayValue, $moduleId);

return new StringSetting($name, $value);
return $this->getCollectionSetting($name, $moduleId);
}

/**
Expand Down
80 changes: 41 additions & 39 deletions tests/Unit/Infrastructure/ModuleSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testGetModuleSettingInteger(): void

$shopServiceReturn = 123;
$moduleRepository = $this->getSut(
moduleSettingService: $this->getShopModuleSettingServiceMock(
moduleSettingService: $this->getShopModuleSettingServiceMethodStub(
'getInteger',
$name,
$moduleId,
Expand All @@ -44,7 +44,7 @@ public function testGetModuleSettingFloat(): void
$moduleId = 'awesomeModule';

$moduleRepository = $this->getSut(
moduleSettingService: $this->getShopModuleSettingServiceMock(
moduleSettingService: $this->getShopModuleSettingServiceMethodStub(
'getFloat',
$name,
$moduleId,
Expand All @@ -65,7 +65,7 @@ public function testGetModuleSettingBoolean(): void
$moduleId = 'awesomeModule';

$moduleRepository = $this->getSut(
moduleSettingService: $this->getShopModuleSettingServiceMock(
moduleSettingService: $this->getShopModuleSettingServiceMethodStub(
'getBoolean',
$name,
$moduleId,
Expand All @@ -86,7 +86,7 @@ public function testGetModuleSettingString(): void
$repositoryReturn = 'default';

$moduleRepository = $this->getSut(
moduleSettingService: $this->getShopModuleSettingServiceMock(
moduleSettingService: $this->getShopModuleSettingServiceMethodStub(
'getString',
$name,
$moduleId,
Expand All @@ -107,7 +107,7 @@ public function testGetModuleSettingCollection(): void
$repositoryReturn = ['nice', 'values'];

$moduleRepository = $this->getSut(
moduleSettingService: $this->getShopModuleSettingServiceMock(
moduleSettingService: $this->getShopModuleSettingServiceMethodStub(
'getCollection',
$name,
$moduleId,
Expand All @@ -121,92 +121,94 @@ public function testGetModuleSettingCollection(): void
);
}

public function testChangeModuleSettingInteger(): void
public function testSaveIntegerSettingProxyingDataToShopService(): void
{
$name = new ID('intSetting');
$name = 'intSetting';
$moduleId = 'awesomeModule';

$callValue = 123;
$moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class);
$moduleSettingService->expects($this->once())
->method('saveInteger')
->with($name->val(), 123, 'awesomeModule');
->with($name, $callValue, $moduleId);

$moduleRepository = $this->getSut(
$moduleSettingService,
$this->createMock(ModuleConfigurationDaoInterface::class)
moduleSettingService: $moduleSettingService
);

$moduleRepository->saveIntegerSetting($name, 123, 'awesomeModule');
$moduleRepository->saveIntegerSetting($name, $callValue, $moduleId);
}

public function testChangeModuleSettingFloat(): void
public function testSaveFloatSettingProxyingDataToShopService(): void
{
$name = new ID('floatSetting');
$name = 'floatSetting';
$moduleId = 'awesomeModule';

$callValue = 1.23;
$moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class);
$moduleSettingService->expects($this->once())
->method('saveFloat')
->with($name->val(), 1.23, 'awesomeModule');
->with($name, $callValue, $moduleId);

$moduleRepository = $this->getSut(
$moduleSettingService,
$this->createMock(ModuleConfigurationDaoInterface::class)
moduleSettingService: $moduleSettingService
);

$moduleRepository->saveFloatSetting($name, 1.23, 'awesomeModule');
$moduleRepository->saveFloatSetting($name, $callValue, $moduleId);
}

public function testChangeModuleSettingBoolean(): void
public function testSaveBooleanSettingProxyingDataToShopService(): void
{
$name = new ID('boolSetting');
$value = false;
$name = 'boolSetting';
$moduleId = 'awesomeModule';

$callValue = false;
$moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class);
$moduleSettingService->expects($this->once())
->method('saveBoolean')
->with($name->val(), $value, 'awesomeModule');
->with($name, $callValue, $moduleId);

$moduleRepository = $this->getSut(
$moduleSettingService,
$this->createMock(ModuleConfigurationDaoInterface::class)
moduleSettingService: $moduleSettingService
);

$moduleRepository->saveBooleanSetting($name, $value, 'awesomeModule');
$moduleRepository->saveBooleanSetting($name, $callValue, $moduleId);
}

public function testChangeModuleSettingString(): void
public function testSaveStringSettingProxyingDataToShopService(): void
{
$name = new ID('stringSetting');
$value = 'default';
$name = 'stringSetting';
$moduleId = 'awesomeModule';

$callValue = 'default';
$moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class);
$moduleSettingService->expects($this->once())
->method('saveString')
->with($name->val(), $value, 'awesomeModule');
->with($name, $callValue, $moduleId);

$moduleRepository = $this->getSut(
$moduleSettingService,
$this->createMock(ModuleConfigurationDaoInterface::class)
moduleSettingService: $moduleSettingService
);

$moduleRepository->saveStringSetting($name, $value, 'awesomeModule');
$moduleRepository->saveStringSetting($name, $callValue, $moduleId);
}

public function testChangeModuleSettingCollection(): void
public function testSaveCollectionSettingProxyingDataToShopService(): void
{
$name = new ID('boolSetting');
$value = [3, 'interesting', 'values'];
$name = 'collectionSetting';
$moduleId = 'awesomeModule';

$callValue = [3, 'interesting', 'values'];
$moduleSettingService = $this->createMock(ModuleSettingServiceInterface::class);
$moduleSettingService->expects($this->once())
->method('saveCollection')
->with($name->val(), $value, 'awesomeModule');
->with($name, $callValue, $moduleId);

$moduleRepository = $this->getSut(
$moduleSettingService,
$this->createMock(ModuleConfigurationDaoInterface::class)
moduleSettingService: $moduleSettingService
);

$moduleRepository->saveCollectionSetting($name, $value, 'awesomeModule');
$moduleRepository->saveCollectionSetting($name, $callValue, $moduleId);
}

public function testGetSettingsList(): void
Expand Down Expand Up @@ -246,7 +248,7 @@ public function getSut(
);
}

private function getShopModuleSettingServiceMock(
private function getShopModuleSettingServiceMethodStub(
string $methodName,
string $name,
string $moduleId,
Expand Down
Loading

0 comments on commit be1f1f1

Please sign in to comment.