-
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.
Merge pull request #1 from qlimix/v2
v2
- Loading branch information
Showing
10 changed files
with
110 additions
and
62 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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
language: php | ||
|
||
php: | ||
- 7.2 | ||
- 7.3 | ||
- 7.4 | ||
- nightly | ||
|
||
matrix: | ||
|
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,10 @@ | ||
## 2.0.0 - 12-03-2020 | ||
|
||
New: | ||
- Added JsonEncoding | ||
|
||
Changed: | ||
- updated encoding dependency to version ^2.0 | ||
|
||
Backward compatibility: | ||
- required PHP >= 7.4 |
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
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,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Qlimix\Encoding; | ||
|
||
use Qlimix\Encoding\Decode\JsonDecode; | ||
use Qlimix\Encoding\Encode\JsonEncode; | ||
|
||
final class JsonEncoding implements EncodingInterface | ||
{ | ||
private JsonDecode $jsonDecode; | ||
private JsonEncode $jsonEncode; | ||
|
||
public function __construct(JsonDecode $jsonDecode, JsonEncode $jsonEncode) | ||
{ | ||
$this->jsonDecode = $jsonDecode; | ||
$this->jsonEncode = $jsonEncode; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function decode(string $value): array | ||
{ | ||
return $this->jsonDecode->decode($value); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function encode(array $value): string | ||
{ | ||
return $this->jsonEncode->encode($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
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,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Qlimix\Tests\Encoding; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Qlimix\Encoding\Decode\Exception\DecodeException; | ||
use Qlimix\Encoding\Decode\JsonDecode; | ||
use Qlimix\Encoding\Encode\JsonEncode; | ||
use Qlimix\Encoding\JsonEncoding; | ||
|
||
final class JsonEncodingTest extends TestCase | ||
{ | ||
private JsonEncoding $jsonEncoding; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->jsonEncoding = new JsonEncoding(new JsonDecode(), new JsonEncode()); | ||
} | ||
|
||
public function testShouldDecode(): void | ||
{ | ||
$this->jsonEncoding->decode('{"foo":"bar"}'); | ||
$this->addToAssertionCount(1); | ||
} | ||
|
||
public function testShouldEncode(): void | ||
{ | ||
$this->jsonEncoding->encode(['foo'=>'bar']); | ||
$this->addToAssertionCount(1); | ||
} | ||
|
||
public function testShouldThrowOnJsonDecodeError(): void | ||
{ | ||
$this->expectException(DecodeException::class); | ||
|
||
$this->jsonEncoding->decode('{foo:"\xB1\x31"}'); | ||
} | ||
} |