-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7557 extract Json service from ThemeSettingService
Signed-off-by: Anton Fedurtsya <[email protected]>
- Loading branch information
Showing
6 changed files
with
125 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\CollectionEncodingException; | ||
|
||
class JsonService implements JsonServiceInterface | ||
{ | ||
/** | ||
* @throws CollectionEncodingException | ||
*/ | ||
public function jsonEncodeArray(array $collection): string | ||
{ | ||
$jsonValue = json_encode($collection); | ||
|
||
if ($jsonValue === false) { | ||
throw new CollectionEncodingException(); | ||
} | ||
return $jsonValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Service; | ||
|
||
interface JsonServiceInterface | ||
{ | ||
public function jsonEncodeArray(array $collection): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Service; | ||
|
||
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\CollectionEncodingException; | ||
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Service\JsonService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class JsonServiceTest extends TestCase | ||
{ | ||
public function testJsonEncodeArray(): void | ||
{ | ||
$sut = new JsonService(); | ||
$value = ['some' => 'value']; | ||
|
||
$this->assertSame('{"some":"value"}', $sut->jsonEncodeArray($value)); | ||
} | ||
|
||
public function testJsonEncodeArrayException(): void | ||
{ | ||
$sut = new JsonService(); | ||
$value = [&$value]; | ||
|
||
$this->expectException(CollectionEncodingException::class); | ||
$sut->jsonEncodeArray($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters