From 36ac9a2f7d617846624c9e0fe62c8ff98b59b07e Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Sat, 16 Dec 2023 21:28:20 +0100 Subject: [PATCH] php 8.3 --- .github/workflows/ci.yml | 24 ++++++------ .gitignore | 1 + README.md | 22 +++++------ composer.json | 39 +++++++++---------- phpunit.xml | 39 +++++++------------ src/Manager/RequestManager.php | 14 ++----- src/Manager/RequestManagerInterface.php | 10 +---- src/Manager/ResponseManager.php | 3 +- .../AcceptAndContentTypeMiddleware.php | 3 +- tests/Unit/Manager/ResponseManagerTest.php | 8 ++-- .../AcceptAndContentTypeMiddlewareTest.php | 8 +--- .../Middleware/ApiExceptionMiddlewareTest.php | 8 +--- 12 files changed, 73 insertions(+), 106 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 282ff32..c07380f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,36 +6,36 @@ on: - cron: '0 0 * * *' jobs: - php80: - name: PHP 8.0 - runs-on: ubuntu-20.04 + php81: + name: PHP 8.1 + runs-on: ubuntu-22.04 steps: - name: checkout uses: actions/checkout@v3 - name: composer test - uses: docker://chubbyphp/ci-php80:latest + uses: docker://chubbyphp/ci-php81:latest env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - php81: - name: PHP 8.1 - runs-on: ubuntu-20.04 + php82: + name: PHP 8.2 + runs-on: ubuntu-22.04 steps: - name: checkout uses: actions/checkout@v3 - name: composer test - uses: docker://chubbyphp/ci-php81:latest + uses: docker://chubbyphp/ci-php82:latest env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - php82: - name: PHP 8.2 - runs-on: ubuntu-20.04 + php83: + name: PHP 8.3 + runs-on: ubuntu-22.04 steps: - name: checkout uses: actions/checkout@v3 - name: composer test - uses: docker://chubbyphp/ci-php82:latest + uses: docker://chubbyphp/ci-php83:latest env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.gitignore b/.gitignore index 1cf303f..91ca7d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .idea/ +.phpunit.cache .vscode/ build/ composer.lock diff --git a/README.md b/README.md index b655d31..9b246bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/chubbyphp/chubbyphp-api-http/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyphp/chubbyphp-api-http/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyphp/chubbyphp-api-http/badge.svg?branch=master)](https://coveralls.io/github/chubbyphp/chubbyphp-api-http?branch=master) -[![Infection MSI](https://badge.stryker-mutator.io/github.com/chubbyphp/chubbyphp-api-http/master)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/chubbyphp-api-http/master) +[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fchubbyphp-api-http%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/chubbyphp-api-http/master)[![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-api-http/v/stable.png)](https://packagist.org/packages/chubbyphp/chubbyphp-api-http) [![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-api-http/v/stable.png)](https://packagist.org/packages/chubbyphp/chubbyphp-api-http) [![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-api-http/downloads.png)](https://packagist.org/packages/chubbyphp/chubbyphp-api-http) [![Monthly Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-api-http/d/monthly)](https://packagist.org/packages/chubbyphp/chubbyphp-api-http) @@ -25,22 +25,22 @@ A simple http handler implementation for API. ## Requirements - * php: ^8.0 - * chubbyphp/chubbyphp-deserialization: ^3.5.1 - * chubbyphp/chubbyphp-http-exception: ^1.0.1 - * chubbyphp/chubbyphp-negotiation: ^1.9 - * chubbyphp/chubbyphp-serialization: ^3.3.1 - * psr/http-factory: ^1.0.1 - * psr/http-message: ^1.0.1 - * psr/http-server-middleware: ^1.0.1 - * psr/log: ^1.1.4|^2.0|^3.0 + * php: ^8.1 + * chubbyphp/chubbyphp-deserialization: ^4.0 + * chubbyphp/chubbyphp-http-exception: ^1.1 + * chubbyphp/chubbyphp-negotiation: ^2.0 + * chubbyphp/chubbyphp-serialization: ^4.0 + * psr/http-factory: ^1.0.2 + * psr/http-message: ^1.1|^2.0 + * psr/http-server-middleware: ^1.0.2 + * psr/log: ^2.0|^3.0 ## Installation Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1]. ```sh -composer require chubbyphp/chubbyphp-api-http "^5.0" +composer require chubbyphp/chubbyphp-api-http "^6.0" ``` ## Usage diff --git a/composer.json b/composer.json index ee81fcc..815fcfc 100644 --- a/composer.json +++ b/composer.json @@ -10,27 +10,26 @@ } ], "require": { - "php": "^8.0", - "chubbyphp/chubbyphp-deserialization": "^3.5.1", - "chubbyphp/chubbyphp-http-exception": "^1.0.1", - "chubbyphp/chubbyphp-negotiation": "^1.9", - "chubbyphp/chubbyphp-serialization": "^3.3.1", - "psr/http-factory": "^1.0.1", - "psr/http-message": "^1.0.1", - "psr/http-server-middleware": "^1.0.1", - "psr/log": "^1.1.4|^2.0|^3.0" + "php": "^8.1", + "chubbyphp/chubbyphp-deserialization": "^4.0", + "chubbyphp/chubbyphp-http-exception": "^1.1", + "chubbyphp/chubbyphp-negotiation": "^2.0", + "chubbyphp/chubbyphp-serialization": "^4.0", + "psr/http-factory": "^1.0.2", + "psr/http-message": "^1.1|^2.0", + "psr/http-server-middleware": "^1.0.2", + "psr/log": "^2.0|^3.0" }, "require-dev": { - "chubbyphp/chubbyphp-container": "^2.1", + "chubbyphp/chubbyphp-container": "^2.2", "chubbyphp/chubbyphp-dev-helper": "dev-master", - "chubbyphp/chubbyphp-laminas-config-factory": "^1.2", - "chubbyphp/chubbyphp-mock": "^1.6.1", - "infection/infection": "^0.26.5", - "php-coveralls/php-coveralls": "^2.5.2", - "phploc/phploc": "^7.0.2", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.4.8", - "phpunit/phpunit": "^9.5.17", + "chubbyphp/chubbyphp-laminas-config-factory": "^1.3", + "chubbyphp/chubbyphp-mock": "^1.7", + "infection/infection": "^0.27.9", + "php-coveralls/php-coveralls": "^2.7", + "phpstan/extension-installer": "^1.3.1", + "phpstan/phpstan": "^1.10.50", + "phpunit/phpunit": "^10.5.3", "pimple/pimple": "^3.5", "psr/container": "^2.0.2" }, @@ -49,7 +48,7 @@ }, "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "6.0-dev" } }, "scripts": { @@ -60,14 +59,12 @@ "@test:integration", "@test:infection", "@test:static-analysis", - "@test:loc", "@test:cs" ], "test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache", "test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=100 --verbose --coverage=build/phpunit", "test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache", "test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log", - "test:loc": "mkdir -p build && vendor/bin/phploc src | tee build/phploc.log", "test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=8 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'", "test:unit": "vendor/bin/phpunit --testsuite=Unit --coverage-text --coverage-clover=build/phpunit/clover.xml --coverage-html=build/phpunit/coverage-html --coverage-xml=build/phpunit/coverage-xml --log-junit=build/phpunit/junit.xml --cache-result-file=build/phpunit/result.cache" } diff --git a/phpunit.xml b/phpunit.xml index 4ea36f1..8d051b4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,26 +1,17 @@ - - - - ./src - - - - - ./tests/Integration - - - ./tests/Unit - - + + + + + ./tests/Integration + + + ./tests/Unit + + + + + ./src + + diff --git a/src/Manager/RequestManager.php b/src/Manager/RequestManager.php index 4989103..385db22 100644 --- a/src/Manager/RequestManager.php +++ b/src/Manager/RequestManager.php @@ -10,27 +10,19 @@ final class RequestManager implements RequestManagerInterface { - public function __construct(private DeserializerInterface $deserializer) - { - } + public function __construct(private DeserializerInterface $deserializer) {} - /** - * @param object|string $object - */ public function getDataFromRequestQuery( ServerRequestInterface $request, - $object, + object|string $object, ?DenormalizerContextInterface $context = null ): object { return $this->deserializer->denormalize($object, $request->getQueryParams(), $context); } - /** - * @param object|string $object - */ public function getDataFromRequestBody( ServerRequestInterface $request, - $object, + object|string $object, string $contentType, ?DenormalizerContextInterface $context = null ): object { diff --git a/src/Manager/RequestManagerInterface.php b/src/Manager/RequestManagerInterface.php index 58cc2ec..f0629f5 100644 --- a/src/Manager/RequestManagerInterface.php +++ b/src/Manager/RequestManagerInterface.php @@ -9,21 +9,15 @@ interface RequestManagerInterface { - /** - * @param object|string $object - */ public function getDataFromRequestQuery( ServerRequestInterface $request, - $object, + object|string $object, ?DenormalizerContextInterface $context = null ): object; - /** - * @param object|string $object - */ public function getDataFromRequestBody( ServerRequestInterface $request, - $object, + object|string $object, string $contentType, ?DenormalizerContextInterface $context = null ): object; diff --git a/src/Manager/ResponseManager.php b/src/Manager/ResponseManager.php index 7a42940..64a4e07 100644 --- a/src/Manager/ResponseManager.php +++ b/src/Manager/ResponseManager.php @@ -15,8 +15,7 @@ final class ResponseManager implements ResponseManagerInterface public function __construct( private ResponseFactoryInterface $responseFactory, private SerializerInterface $serializer - ) { - } + ) {} public function create( object $object, diff --git a/src/Middleware/AcceptAndContentTypeMiddleware.php b/src/Middleware/AcceptAndContentTypeMiddleware.php index a061d17..9ed7d88 100644 --- a/src/Middleware/AcceptAndContentTypeMiddleware.php +++ b/src/Middleware/AcceptAndContentTypeMiddleware.php @@ -19,8 +19,7 @@ public function __construct( private AcceptNegotiatorInterface $acceptNegotiator, private ContentTypeNegotiatorInterface $contentTypeNegotiator, private ResponseManagerInterface $responseManager - ) { - } + ) {} public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/tests/Unit/Manager/ResponseManagerTest.php b/tests/Unit/Manager/ResponseManagerTest.php index 90635ce..63506bc 100644 --- a/tests/Unit/Manager/ResponseManagerTest.php +++ b/tests/Unit/Manager/ResponseManagerTest.php @@ -33,7 +33,7 @@ public function testCreateWithDefaults(): void /** @var MockObject|StreamInterface $body */ $body = $this->getMockByCalls(StreamInterface::class, [ - Call::create('write')->with($bodyString), + Call::create('write')->with($bodyString)->willReturn(\strlen($bodyString)), ]); /** @var MockObject|Response $response */ @@ -65,7 +65,7 @@ public function testCreateWithoutDefaults(): void /** @var MockObject|StreamInterface $body */ $body = $this->getMockByCalls(StreamInterface::class, [ - Call::create('write')->with($bodyString), + Call::create('write')->with($bodyString)->willReturn(\strlen($bodyString)), ]); /** @var MockObject|Response $response */ @@ -174,11 +174,13 @@ public function testCreateRedirectWithoutDefaults(): void public function testCreateFromHttpException(): void { + $bodyString = '{"title":"Method Not Allowed"}'; + $httpException = HttpException::createMethodNotAllowed(['allowedMethods' => ['PATCH', 'PUT']]); /** @var MockObject|StreamInterface $body */ $body = $this->getMockByCalls(StreamInterface::class, [ - Call::create('write')->with('{"title":"Method Not Allowed"}'), + Call::create('write')->with($bodyString)->willReturn(\strlen($bodyString)), ]); /** @var MockObject|Response $response */ diff --git a/tests/Unit/Middleware/AcceptAndContentTypeMiddlewareTest.php b/tests/Unit/Middleware/AcceptAndContentTypeMiddlewareTest.php index 2880772..349b008 100644 --- a/tests/Unit/Middleware/AcceptAndContentTypeMiddlewareTest.php +++ b/tests/Unit/Middleware/AcceptAndContentTypeMiddlewareTest.php @@ -138,9 +138,7 @@ public function testWithAccept(): void $response = $this->getMockByCalls(ResponseInterface::class, []); $requestHandler = new class($response) implements RequestHandlerInterface { - public function __construct(private ResponseInterface $response) - { - } + public function __construct(private ResponseInterface $response) {} public function handle(ServerRequestInterface $request): ResponseInterface { @@ -298,9 +296,7 @@ public function testWithContentType(): void $response = $this->getMockByCalls(ResponseInterface::class, []); $requestHandler = new class($response) implements RequestHandlerInterface { - public function __construct(private ResponseInterface $response) - { - } + public function __construct(private ResponseInterface $response) {} public function handle(ServerRequestInterface $request): ResponseInterface { diff --git a/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php b/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php index 66aad61..85b1334 100644 --- a/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php +++ b/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php @@ -36,9 +36,7 @@ public function testWithoutExceptionWithDebugWithLogger(): void $response = $this->getMockByCalls(ResponseInterface::class); $requestHandler = new class($response) implements RequestHandlerInterface { - public function __construct(private ResponseInterface $response) - { - } + public function __construct(private ResponseInterface $response) {} public function handle(ServerRequestInterface $request): ResponseInterface { @@ -130,9 +128,7 @@ public function testWithHttpExceptionWithDebugWithLogger(): void $response = $this->getMockByCalls(ResponseInterface::class); $requestHandler = new class($httpException) implements RequestHandlerInterface { - public function __construct(private HttpExceptionInterface $httpException) - { - } + public function __construct(private HttpExceptionInterface $httpException) {} public function handle(ServerRequestInterface $request): ResponseInterface {