From 5982bb1214353868b56a77994dd9b6fa60450714 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Mon, 24 Apr 2023 16:39:54 +0200 Subject: [PATCH 1/2] Improve decoder testing --- tests/unit/DecodersTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/DecodersTest.php b/tests/unit/DecodersTest.php index ec8502d..b725a3d 100644 --- a/tests/unit/DecodersTest.php +++ b/tests/unit/DecodersTest.php @@ -33,6 +33,17 @@ public function testMap(): void self::assertSame($i, $a->getValue()); }); } + + public function testStringDecoder(): void + { + /** @psalm-var string $input */ + $input = 'hello'; + + self::asserSuccessSameTo( + $input, + Decoders::string()->decode($input) + ); + } } namespace Tests\Facile\PhpCodec\DecodersTest; From 1ef1642881fbe667f8522a2836ff28e5818eb83e Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Mon, 24 Apr 2023 17:16:53 +0200 Subject: [PATCH 2/2] up --- composer.json | 2 +- tests/unit/DecodersTest.php | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2df02cd..0822ba2 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "require-dev": { "phpunit/phpunit": "^9", - "giorgiosironi/eris": "^0.14.0", + "giorgiosironi/eris": "dev-master", "phpat/phpat": "^0.10", "facile-it/facile-coding-standard": "0.5.2", "vimeo/psalm": "4.30.0", diff --git a/tests/unit/DecodersTest.php b/tests/unit/DecodersTest.php index b725a3d..c5c4be3 100644 --- a/tests/unit/DecodersTest.php +++ b/tests/unit/DecodersTest.php @@ -44,6 +44,46 @@ public function testStringDecoder(): void Decoders::string()->decode($input) ); } + + public function testNullDecoder(): void + { + self::asserSuccessSameTo( + null, + Decoders::null()->decode(null) + ); + } + + public function testMixedDecoder(): void + { + $d = Decoders::mixed(); + + $this + ->forAll( + Generators::oneOf( + Generators::int(), + Generators::string(), + Generators::bool(), + Generators::constant(null), + Generators::tuple([ + 'a' => Generators::int(), + 'b' => Generators::string(), + ]), + Generators::date() + ) + ) + ->then( + /** + * @psalm-param mixed $any + * + * @psalm-return void + * + * @param mixed $any + */ + function ($any) use ($d): void { + self::asserSuccessSameTo($any, $d->decode($any)); + } + ); + } } namespace Tests\Facile\PhpCodec\DecodersTest;