diff --git a/README.md b/README.md index f1773b5..9cde37f 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.19 + * chubbyphp/chubbyphp-deserialization: ^3.0 * chubbyphp/chubbyphp-negotiation: ^1.7 - * chubbyphp/chubbyphp-serialization: ^2.15 + * 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.6" +composer require chubbyphp/chubbyphp-api-http "^4.0" ``` ## Usage diff --git a/composer.json b/composer.json index 2740304..bdc0c33 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": "^7.2", - "chubbyphp/chubbyphp-deserialization": "^2.19", + "chubbyphp/chubbyphp-deserialization": "^3.0", "chubbyphp/chubbyphp-negotiation": "^1.7", - "chubbyphp/chubbyphp-serialization": "^2.15", + "chubbyphp/chubbyphp-serialization": "^3.0", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", "psr/http-server-middleware": "^1.0.1", @@ -44,7 +44,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.6-dev" + "dev-master": "4.0-dev" } }, "scripts": { diff --git a/src/Container/AcceptAndContentTypeMiddlewareFactory.php b/src/Container/AcceptAndContentTypeMiddlewareFactory.php deleted file mode 100644 index 5532523..0000000 --- a/src/Container/AcceptAndContentTypeMiddlewareFactory.php +++ /dev/null @@ -1,26 +0,0 @@ -get(AcceptNegotiatorInterface::class), - $container->get(ContentTypeNegotiatorInterface::class), - $container->get(ResponseManagerInterface::class) - ); - } -} diff --git a/src/Container/ApiExceptionMiddlewareFactory.php b/src/Container/ApiExceptionMiddlewareFactory.php deleted file mode 100644 index f831379..0000000 --- a/src/Container/ApiExceptionMiddlewareFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(ResponseManagerInterface::class), - $container->get('config')['debug'], - $container->get(LoggerInterface::class) - ); - } -} diff --git a/src/Container/RequestManagerFactory.php b/src/Container/RequestManagerFactory.php deleted file mode 100644 index 6c79784..0000000 --- a/src/Container/RequestManagerFactory.php +++ /dev/null @@ -1,23 +0,0 @@ -get(DeserializerInterface::class) - ); - } -} diff --git a/src/Container/ResponseManagerFactory.php b/src/Container/ResponseManagerFactory.php deleted file mode 100644 index 925a937..0000000 --- a/src/Container/ResponseManagerFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -get(ResponseFactoryInterface::class), - $container->get(SerializerInterface::class) - ); - } -} 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/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/Container/AcceptAndContentTypeMiddlewareFactoryTest.php b/tests/Unit/Container/AcceptAndContentTypeMiddlewareFactoryTest.php deleted file mode 100644 index e5e53d5..0000000 --- a/tests/Unit/Container/AcceptAndContentTypeMiddlewareFactoryTest.php +++ /dev/null @@ -1,50 +0,0 @@ -getMockByCalls(AcceptNegotiatorInterface::class); - - /** @var ContentTypeNegotiatorInterface $contentTypeNegotiator */ - $contentTypeNegotiator = $this->getMockByCalls(ContentTypeNegotiatorInterface::class); - - /** @var ResponseManagerInterface $responseManager */ - $responseManager = $this->getMockByCalls(ResponseManagerInterface::class); - - /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(AcceptNegotiatorInterface::class)->willReturn($acceptNegotiator), - Call::create('get')->with(ContentTypeNegotiatorInterface::class)->willReturn($contentTypeNegotiator), - Call::create('get')->with(ResponseManagerInterface::class)->willReturn($responseManager), - ]); - - $factory = new AcceptAndContentTypeMiddlewareFactory(); - - $acceptAndContentTypeMiddleware = $factory($container); - - self::assertInstanceOf(AcceptAndContentTypeMiddleware::class, $acceptAndContentTypeMiddleware); - } -} diff --git a/tests/Unit/Container/ApiExceptionMiddlewareFactoryTest.php b/tests/Unit/Container/ApiExceptionMiddlewareFactoryTest.php deleted file mode 100644 index 8370ac3..0000000 --- a/tests/Unit/Container/ApiExceptionMiddlewareFactoryTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getMockByCalls(ResponseManagerInterface::class); - - /** @var LoggerInterface $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class); - - /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(ResponseManagerInterface::class)->willReturn($responseManager), - Call::create('get')->with('config')->willReturn(['debug' => true]), - Call::create('get')->with(LoggerInterface::class)->willReturn($logger), - ]); - - $factory = new ApiExceptionMiddlewareFactory(); - - $apiExceptionMiddleware = $factory($container); - - self::assertInstanceOf(ApiExceptionMiddleware::class, $apiExceptionMiddleware); - } -} diff --git a/tests/Unit/Container/RequestManagerFactoryTest.php b/tests/Unit/Container/RequestManagerFactoryTest.php deleted file mode 100644 index 548ddff..0000000 --- a/tests/Unit/Container/RequestManagerFactoryTest.php +++ /dev/null @@ -1,40 +0,0 @@ -getMockByCalls(DeserializerInterface::class); - - /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(DeserializerInterface::class)->willReturn($deserializer), - ]); - - $factory = new RequestManagerFactory(); - - $requestManager = $factory($container); - - self::assertInstanceOf(RequestManagerInterface::class, $requestManager); - } -} diff --git a/tests/Unit/Container/ResponseManagerFactoryTest.php b/tests/Unit/Container/ResponseManagerFactoryTest.php deleted file mode 100644 index 574f796..0000000 --- a/tests/Unit/Container/ResponseManagerFactoryTest.php +++ /dev/null @@ -1,45 +0,0 @@ -getMockByCalls(ResponseFactoryInterface::class); - - /** @var SerializerInterface $serializer */ - $serializer = $this->getMockByCalls(SerializerInterface::class); - - /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory), - Call::create('get')->with(SerializerInterface::class)->willReturn($serializer), - ]); - - $factory = new ResponseManagerFactory(); - - $responseManager = $factory($container); - - self::assertInstanceOf(ResponseManagerInterface::class, $responseManager); - } -} 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"}'; 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']; - } -}