Skip to content

Commit

Permalink
OXDEV-7646 Remove usage of ID in Module setting chains
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
  • Loading branch information
Sieg committed Dec 4, 2023
1 parent eac35e1 commit 4ed1125
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 70 deletions.
21 changes: 10 additions & 11 deletions src/Setting/Controller/ModuleSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\GraphQLite\Annotations\Right;
use TheCodingMachine\GraphQLite\Types\ID;

final class ModuleSettingController
{
Expand All @@ -33,7 +32,7 @@ public function __construct(
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getModuleSettingInteger(ID $name, string $moduleId): IntegerSetting
public function getModuleSettingInteger(string $name, string $moduleId): IntegerSetting
{
return $this->moduleSettingService->getIntegerSetting($name, $moduleId);
}
Expand All @@ -42,7 +41,7 @@ public function getModuleSettingInteger(ID $name, string $moduleId): IntegerSett
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getModuleSettingFloat(ID $name, string $moduleId): FloatSetting
public function getModuleSettingFloat(string $name, string $moduleId): FloatSetting
{
return $this->moduleSettingService->getFloatSetting($name, $moduleId);
}
Expand All @@ -51,7 +50,7 @@ public function getModuleSettingFloat(ID $name, string $moduleId): FloatSetting
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getModuleSettingBoolean(ID $name, string $moduleId): BooleanSetting
public function getModuleSettingBoolean(string $name, string $moduleId): BooleanSetting
{
return $this->moduleSettingService->getBooleanSetting($name, $moduleId);
}
Expand All @@ -60,7 +59,7 @@ public function getModuleSettingBoolean(ID $name, string $moduleId): BooleanSett
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getModuleSettingString(ID $name, string $moduleId): StringSetting
public function getModuleSettingString(string $name, string $moduleId): StringSetting
{
return $this->moduleSettingService->getStringSetting($name, $moduleId);
}
Expand All @@ -69,7 +68,7 @@ public function getModuleSettingString(ID $name, string $moduleId): StringSettin
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getModuleSettingCollection(ID $name, string $moduleId): StringSetting
public function getModuleSettingCollection(string $name, string $moduleId): StringSetting
{
return $this->moduleSettingService->getCollectionSetting($name, $moduleId);
}
Expand All @@ -78,7 +77,7 @@ public function getModuleSettingCollection(ID $name, string $moduleId): StringSe
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeModuleSettingInteger(ID $name, int $value, string $moduleId): IntegerSetting
public function changeModuleSettingInteger(string $name, int $value, string $moduleId): IntegerSetting
{
return $this->moduleSettingService->changeIntegerSetting($name, $value, $moduleId);
}
Expand All @@ -87,7 +86,7 @@ public function changeModuleSettingInteger(ID $name, int $value, string $moduleI
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeModuleSettingFloat(ID $name, float $value, string $moduleId): FloatSetting
public function changeModuleSettingFloat(string $name, float $value, string $moduleId): FloatSetting
{
return $this->moduleSettingService->changeFloatSetting($name, $value, $moduleId);
}
Expand All @@ -96,7 +95,7 @@ public function changeModuleSettingFloat(ID $name, float $value, string $moduleI
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeModuleSettingBoolean(ID $name, bool $value, string $moduleId): BooleanSetting
public function changeModuleSettingBoolean(string $name, bool $value, string $moduleId): BooleanSetting
{
return $this->moduleSettingService->changeBooleanSetting($name, $value, $moduleId);
}
Expand All @@ -105,7 +104,7 @@ public function changeModuleSettingBoolean(ID $name, bool $value, string $module
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeModuleSettingString(ID $name, string $value, string $moduleId): StringSetting
public function changeModuleSettingString(string $name, string $value, string $moduleId): StringSetting
{
return $this->moduleSettingService->changeStringSetting($name, $value, $moduleId);
}
Expand All @@ -114,7 +113,7 @@ public function changeModuleSettingString(ID $name, string $value, string $modul
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeModuleSettingCollection(ID $name, string $value, string $moduleId): StringSetting
public function changeModuleSettingCollection(string $name, string $value, string $moduleId): StringSetting
{
return $this->moduleSettingService->changeCollectionSetting($name, $value, $moduleId);
}
Expand Down
30 changes: 15 additions & 15 deletions src/Setting/Service/ModuleSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,77 @@ public function __construct(
) {
}

public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting
public function getIntegerSetting(string $name, string $moduleId): IntegerSetting
{
return new IntegerSetting(
$name,
new ID($name),
$this->moduleSettingRepository->getIntegerSetting((string)$name, $moduleId)
);
}

public function getFloatSetting(ID $name, string $moduleId): FloatSetting
public function getFloatSetting(string $name, string $moduleId): FloatSetting
{
return new FloatSetting(
$name,
new ID($name),
$this->moduleSettingRepository->getFloatSetting((string)$name, $moduleId)
);
}

public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting
public function getBooleanSetting(string $name, string $moduleId): BooleanSetting
{
return new BooleanSetting(
$name,
new ID($name),
$this->moduleSettingRepository->getBooleanSetting((string)$name, $moduleId)
);
}

public function getStringSetting(ID $name, string $moduleId): StringSetting
public function getStringSetting(string $name, string $moduleId): StringSetting
{
return new StringSetting(
$name,
new ID($name),
$this->moduleSettingRepository->getStringSetting((string)$name, $moduleId)
);
}

public function getCollectionSetting(ID $name, string $moduleId): StringSetting
public function getCollectionSetting(string $name, string $moduleId): StringSetting
{
$collection = $this->moduleSettingRepository->getCollectionSetting((string)$name, $moduleId);

return new StringSetting(
$name,
new ID($name),
$this->jsonService->jsonEncodeArray($collection)
);
}

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

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

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

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

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

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

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

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

public function changeCollectionSetting(ID $name, string $value, string $moduleId): StringSetting
public function changeCollectionSetting(string $name, string $value, string $moduleId): StringSetting
{
$this->moduleSettingRepository->saveCollectionSetting(
(string)$name,
Expand Down
21 changes: 10 additions & 11 deletions src/Setting/Service/ModuleSettingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\SettingType;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use TheCodingMachine\GraphQLite\Types\ID;

interface ModuleSettingServiceInterface
{
public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting;
public function getIntegerSetting(string $name, string $moduleId): IntegerSetting;

public function getFloatSetting(ID $name, string $moduleId): FloatSetting;
public function getFloatSetting(string $name, string $moduleId): FloatSetting;

public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting;
public function getBooleanSetting(string $name, string $moduleId): BooleanSetting;

public function getStringSetting(ID $name, string $moduleId): StringSetting;
public function getStringSetting(string $name, string $moduleId): StringSetting;

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

public function changeIntegerSetting(ID $name, int $value, string $moduleId): IntegerSetting;
public function changeIntegerSetting(string $name, int $value, string $moduleId): IntegerSetting;

public function changeFloatSetting(ID $name, float $value, string $moduleId): FloatSetting;
public function changeFloatSetting(string $name, float $value, string $moduleId): FloatSetting;

public function changeBooleanSetting(ID $name, bool $value, string $moduleId): BooleanSetting;
public function changeBooleanSetting(string $name, bool $value, string $moduleId): BooleanSetting;

public function changeStringSetting(ID $name, string $value, string $moduleId): StringSetting;
public function changeStringSetting(string $name, string $value, string $moduleId): StringSetting;

public function changeCollectionSetting(ID $name, string $value, string $moduleId): StringSetting;
public function changeCollectionSetting(string $name, string $value, string $moduleId): StringSetting;

/**
* @return SettingType[]
Expand Down
2 changes: 1 addition & 1 deletion tests/Codeception/Acceptance/ModuleSettingGettersCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function queryMethodsDataProvider(): \Generator
private function runSettingGetterQuery(AcceptanceTester $I, string $queryName, string $settingName): array
{
$I->sendGQLQuery(
'query q($name: ID!, $moduleId: String!){
'query q($name: String!, $moduleId: String!){
' . $queryName . '(name: $name, moduleId: $moduleId) {
name
value
Expand Down
10 changes: 5 additions & 5 deletions tests/Codeception/Acceptance/ModuleSettingMutationsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: Int!, $moduleId: String!){
'mutation m($name: String!, $value: Int!, $moduleId: String!){
changeModuleSettingInteger(name: $name, value: $value, moduleId: $moduleId) {
name
value
Expand Down Expand Up @@ -52,7 +52,7 @@ public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: Float!, $moduleId: String!){
'mutation m($name: String!, $value: Float!, $moduleId: String!){
changeModuleSettingFloat(name: $name, value: $value, moduleId: $moduleId) {
name
value
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: Boolean!, $moduleId: String!){
'mutation m($name: String!, $value: Boolean!, $moduleId: String!){
changeModuleSettingBoolean(name: $name, value: $value, moduleId: $moduleId) {
name
value
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testChangeStringSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: String!, $moduleId: String!){
'mutation m($name: String!, $value: String!, $moduleId: String!){
changeModuleSettingString(name: $name, value: $value, moduleId: $moduleId) {
name
value
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'mutation m($name: ID!, $value: String!, $moduleId: String!){
'mutation m($name: String!, $value: String!, $moduleId: String!){
changeModuleSettingCollection(name: $name, value: $value, moduleId: $moduleId) {
name
value
Expand Down
25 changes: 13 additions & 12 deletions tests/Unit/Controller/ModuleSettingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,82 +42,83 @@ public function testControllerProxiesParametersToServiceAndReturnsItsResult(

public function proxyTestDataProvider(): \Generator
{
$settingNameID = new ID('settingName');
$settingName = 'settingName';
$settingNameID = new ID($settingName);

yield 'getter integer' => [
'controllerMethod' => 'getModuleSettingInteger',
'serviceMethod' => 'getIntegerSetting',
'params' => [$settingNameID, 'awesomeModule'],
'params' => [$settingName, 'awesomeModule'],
'expectedValue' => new IntegerSetting($settingNameID, 123)
];

yield 'getter float' => [
'controllerMethod' => 'getModuleSettingFloat',
'serviceMethod' => 'getFloatSetting',
'params' => [$settingNameID, 'awesomeModule'],
'params' => [$settingName, 'awesomeModule'],
'expectedValue' => new FloatSetting($settingNameID, 1.23)
];

yield 'getter bool' => [
'controllerMethod' => 'getModuleSettingBoolean',
'serviceMethod' => 'getBooleanSetting',
'params' => [$settingNameID, 'awesomeModule'],
'params' => [$settingName, 'awesomeModule'],
'expectedValue' => new BooleanSetting($settingNameID, false)
];

yield 'getter string' => [
'controllerMethod' => 'getModuleSettingString',
'serviceMethod' => 'getStringSetting',
'params' => [$settingNameID, 'awesomeModule'],
'params' => [$settingName, 'awesomeModule'],
'expectedValue' => new StringSetting($settingNameID, 'default')
];

yield 'getter collection' => [
'controllerMethod' => 'getModuleSettingCollection',
'serviceMethod' => 'getCollectionSetting',
'params' => [$settingNameID, 'awesomeModule'],
'params' => [$settingName, 'awesomeModule'],
'expectedValue' => new StringSetting($settingNameID, 'someCollectionStringExample')
];

yield 'setter integer' => [
'controllerMethod' => 'changeModuleSettingInteger',
'serviceMethod' => 'changeIntegerSetting',
'params' => [$settingNameID, 123, 'awesomeModule'],
'params' => [$settingName, 123, 'awesomeModule'],
'expectedValue' => new IntegerSetting($settingNameID, 123)
];

yield 'setter float' => [
'controllerMethod' => 'changeModuleSettingFloat',
'serviceMethod' => 'changeFloatSetting',
'params' => [$settingNameID, 1.23, 'awesomeModule'],
'params' => [$settingName, 1.23, 'awesomeModule'],
'expectedValue' => new FloatSetting($settingNameID, 1.23)
];

yield 'setter float with integer value' => [
'controllerMethod' => 'changeModuleSettingFloat',
'serviceMethod' => 'changeFloatSetting',
'params' => [$settingNameID, 123, 'awesomeModule'],
'params' => [$settingName, 123, 'awesomeModule'],
'expectedValue' => new FloatSetting($settingNameID, 123)
];

yield 'setter boolean' => [
'controllerMethod' => 'changeModuleSettingBoolean',
'serviceMethod' => 'changeBooleanSetting',
'params' => [$settingNameID, false, 'awesomeModule'],
'params' => [$settingName, false, 'awesomeModule'],
'expectedValue' => new BooleanSetting($settingNameID, false)
];

yield 'setter string' => [
'controllerMethod' => 'changeModuleSettingString',
'serviceMethod' => 'changeStringSetting',
'params' => [$settingNameID, 'some string', 'awesomeModule'],
'params' => [$settingName, 'some string', 'awesomeModule'],
'expectedValue' => new StringSetting($settingNameID, 'some string')
];

yield 'setter collection' => [
'controllerMethod' => 'changeModuleSettingCollection',
'serviceMethod' => 'changeCollectionSetting',
'params' => [$settingNameID, 'some collection string', 'awesomeModule'],
'params' => [$settingName, 'some collection string', 'awesomeModule'],
'expectedValue' => new StringSetting($settingNameID, 'some collection string')
];

Expand Down
Loading

0 comments on commit 4ed1125

Please sign in to comment.