From 7e4bf8f991cee653898edee23593c76a9ea56043 Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Sun, 5 Jul 2020 18:49:26 +0200 Subject: [PATCH 1/3] v4 --- README.md | 6 +-- composer.json | 6 +-- src/Manager/ResponseManager.php | 28 ++------------ tests/Unit/Manager/ResponseManagerTest.php | 45 ---------------------- 4 files changed, 9 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 4e101ac..2cedb9e 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ A simple http handler implementation for API. ## Requirements * php: ^7.2 - * chubbyphp/chubbyphp-deserialization: ^2.17.1 + * chubbyphp/chubbyphp-deserialization: ^3.0 * chubbyphp/chubbyphp-negotiation: ^1.5.3 - * chubbyphp/chubbyphp-serialization: ^2.13.2 + * chubbyphp/chubbyphp-serialization: ^3.0 * psr/http-factory: ^1.0.1 * psr/http-message: ^1.0.1 * psr/http-server-middleware: ^1.0.1 @@ -27,7 +27,7 @@ A simple http handler implementation for API. Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1]. ```sh -composer require chubbyphp/chubbyphp-api-http "^3.4" +composer require chubbyphp/chubbyphp-api-http "^4.0" ``` ## Usage diff --git a/composer.json b/composer.json index 760febe..25623d4 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": "^7.2", - "chubbyphp/chubbyphp-deserialization": "^2.17.1", + "chubbyphp/chubbyphp-deserialization": "^3.0@dev", "chubbyphp/chubbyphp-negotiation": "^1.5.3", - "chubbyphp/chubbyphp-serialization": "^2.13.2", + "chubbyphp/chubbyphp-serialization": "^3.0@dev", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", "psr/http-server-middleware": "^1.0.1", @@ -43,7 +43,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.0-dev" } }, "scripts": { diff --git a/src/Manager/ResponseManager.php b/src/Manager/ResponseManager.php index 6cdf61e..4df943b 100644 --- a/src/Manager/ResponseManager.php +++ b/src/Manager/ResponseManager.php @@ -5,7 +5,6 @@ namespace Chubbyphp\ApiHttp\Manager; use Chubbyphp\ApiHttp\ApiProblem\ApiProblemInterface; -use Chubbyphp\Deserialization\DeserializerInterface; use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; use Chubbyphp\Serialization\SerializerInterface; use Psr\Http\Message\ResponseFactoryInterface; @@ -23,21 +22,10 @@ final class ResponseManager implements ResponseManagerInterface */ private $serializer; - public function __construct() + public function __construct(ResponseFactoryInterface $responseFactory, SerializerInterface $serializer) { - $args = func_get_args(); - - if ($args[0] instanceof DeserializerInterface) { - @trigger_error( - 'Remove deserializer as first argument.', - E_USER_DEPRECATED - ); - - array_shift($args); - } - - $this->setResponseFactory($args[0]); - $this->setSerializer($args[1]); + $this->responseFactory = $responseFactory; + $this->serializer = $serializer; } /** @@ -88,14 +76,4 @@ public function createFromApiProblem( return $response; } - - private function setResponseFactory(ResponseFactoryInterface $responseFactory): void - { - $this->responseFactory = $responseFactory; - } - - private function setSerializer(SerializerInterface $serializer): void - { - $this->serializer = $serializer; - } } diff --git a/tests/Unit/Manager/ResponseManagerTest.php b/tests/Unit/Manager/ResponseManagerTest.php index b6db164..8270ae7 100644 --- a/tests/Unit/Manager/ResponseManagerTest.php +++ b/tests/Unit/Manager/ResponseManagerTest.php @@ -6,7 +6,6 @@ use Chubbyphp\ApiHttp\ApiProblem\ApiProblemInterface; use Chubbyphp\ApiHttp\Manager\ResponseManager; -use Chubbyphp\Deserialization\DeserializerInterface; use Chubbyphp\Mock\Call; use Chubbyphp\Mock\MockByCallsTrait; use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; @@ -26,50 +25,6 @@ final class ResponseManagerTest extends TestCase { use MockByCallsTrait; - public function testCreateWithDefaultsAndDeserializer(): void - { - $bodyString = '{"key": "value"}'; - - $object = new \stdClass(); - - /** @var DeserializerInterface|MockObject $deserializer */ - $deserializer = $this->getMockByCalls(DeserializerInterface::class); - - /** @var StreamInterface|MockObject $body */ - $body = $this->getMockByCalls(StreamInterface::class, [ - Call::create('write')->with($bodyString), - ]); - - /** @var Response|MockObject $response */ - $response = $this->getMockByCalls(Response::class, [ - Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(), - Call::create('getBody')->with()->willReturn($body), - ]); - - /** @var ResponseFactoryInterface|MockObject $responseFactory */ - $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [ - Call::create('createResponse')->with(200, '')->willReturn($response), - ]); - - /** @var SerializerInterface|MockObject $serializer */ - $serializer = $this->getMockByCalls(SerializerInterface::class, [ - Call::create('serialize')->with($object, 'application/json', null, '')->willReturn($bodyString), - ]); - - error_clear_last(); - - $responseManager = new ResponseManager($deserializer, $responseFactory, $serializer); - - $error = error_get_last(); - - self::assertNotNull($error); - - self::assertSame(E_USER_DEPRECATED, $error['type']); - self::assertSame('Remove deserializer as first argument.', $error['message']); - - self::assertSame($response, $responseManager->create($object, 'application/json')); - } - public function testCreateWithDefaults(): void { $bodyString = '{"key": "value"}'; From d529e2175a45b072a3bce9e1503e193760a970bb Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Thu, 10 Sep 2020 21:07:12 +0200 Subject: [PATCH 2/3] drop provider --- src/Provider/ApiHttpProvider.php | 27 ---------- tests/Unit/Provider/ApiHttpProviderTest.php | 58 --------------------- 2 files changed, 85 deletions(-) delete mode 100644 src/Provider/ApiHttpProvider.php delete mode 100644 tests/Unit/Provider/ApiHttpProviderTest.php diff --git a/src/Provider/ApiHttpProvider.php b/src/Provider/ApiHttpProvider.php deleted file mode 100644 index d8c9102..0000000 --- a/src/Provider/ApiHttpProvider.php +++ /dev/null @@ -1,27 +0,0 @@ -serviceProvider = new ApiHttpServiceProvider(); - } - - public function register(Container $container): void - { - $this->serviceProvider->register($container); - } -} diff --git a/tests/Unit/Provider/ApiHttpProviderTest.php b/tests/Unit/Provider/ApiHttpProviderTest.php deleted file mode 100644 index 4760fab..0000000 --- a/tests/Unit/Provider/ApiHttpProviderTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getMockByCalls(ResponseFactoryInterface::class); - - $container = new Container(); - $container->register(new ApiHttpProvider()); - $container->register(new DeserializationProvider()); - $container->register(new SerializationProvider()); - - $container['api-http.response.factory'] = function () use ($responseFactory) { - return $responseFactory; - }; - - self::assertTrue(isset($container['api-http.response.manager'])); - self::assertTrue(isset($container['api-http.response.factory'])); - - self::assertInstanceOf(RequestManager::class, $container['api-http.request.manager']); - self::assertInstanceOf(ResponseManager::class, $container['api-http.response.manager']); - self::assertSame($responseFactory, $container['api-http.response.factory']); - } - - public function testFactoryExpectException(): void - { - self::expectException(\RuntimeException::class); - self::expectExceptionMessage('Missing response factory, define service "api-http.response.factory"'); - - $container = new Container(); - $container->register(new ApiHttpProvider()); - - $container['api-http.response.factory']; - } -} From 47877975a8763d8c03ece6c04000abace750acf6 Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Sun, 20 Sep 2020 11:46:53 +0200 Subject: [PATCH 3/3] use (de)serialization v3 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 15d1fee..bdc0c33 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": "^7.2", - "chubbyphp/chubbyphp-deserialization": "^3.0@dev", + "chubbyphp/chubbyphp-deserialization": "^3.0", "chubbyphp/chubbyphp-negotiation": "^1.7", - "chubbyphp/chubbyphp-serialization": "^3.0@dev", + "chubbyphp/chubbyphp-serialization": "^3.0", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", "psr/http-server-middleware": "^1.0.1",