From d4676b667ce993e5febc3f52ed83fb542a304b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Wed, 30 Jun 2021 12:00:30 +0200 Subject: [PATCH] IBX-688: \eZ\Publish\Core\Repository\SettingService::buildSettingDomainObject deserialize hashes as stdClass --- .../Repository/Tests/SettingServiceTest.php | 51 +++++++++++++++++-- eZ/Publish/Core/Repository/SettingService.php | 2 +- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/SettingServiceTest.php b/eZ/Publish/API/Repository/Tests/SettingServiceTest.php index a061782e5a..441e77efd4 100644 --- a/eZ/Publish/API/Repository/Tests/SettingServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/SettingServiceTest.php @@ -47,24 +47,65 @@ protected function setUp(): void /** * @covers \eZ\Publish\API\Repository\SettingService::createSetting() + * + * @dataProvider dataProviderForCreateSetting */ - public function testCreateSetting(): void + public function testCreateSetting(string $identifier, $value): void { $settingService = $this->getSettingService(); $settingCreate = $settingService->newSettingCreateStruct(); $settingCreate->setGroup('test_group'); - $settingCreate->setIdentifier('test_identifier'); - $settingCreate->setValue('test_value'); + $settingCreate->setIdentifier($identifier); + $settingCreate->setValue($value); $setting = $settingService->createSetting($settingCreate); + self::assertEquals(new Setting([ 'group' => 'test_group', - 'identifier' => 'test_identifier', - 'value' => 'test_value', + 'identifier' => $identifier, + 'value' => $value, ]), $setting); } + public function dataProviderForCreateSetting(): iterable + { + yield 'null' => [ + 'example_null', + null, + ]; + + yield 'boolean' => [ + 'example_boolean', + true, + ]; + + yield 'string' => [ + 'example_string', + 'string', + ]; + + yield 'int' => [ + 'example_int', + 2, + ]; + + yield 'float' => [ + 'example_number', + 3.14, + ]; + + yield 'array' => [ + 'example_hash', + [ + 'foo' => 'foo', + 'bar' => 2, + 'baz' => 3.14, + 'foobar' => range(1, 10), + ], + ]; + } + /** * @covers \eZ\Publish\API\Repository\SettingService::createSetting() */ diff --git a/eZ/Publish/Core/Repository/SettingService.php b/eZ/Publish/Core/Repository/SettingService.php index 056a0383a0..510ae90075 100644 --- a/eZ/Publish/Core/Repository/SettingService.php +++ b/eZ/Publish/Core/Repository/SettingService.php @@ -125,7 +125,7 @@ private function buildSettingDomainObject(SPISetting $setting): Setting return new Setting([ 'group' => $setting->group, 'identifier' => $setting->identifier, - 'value' => json_decode($setting->serializedValue), + 'value' => json_decode($setting->serializedValue, true), ]); } }