From 4404a85b92eae687e660bad7f7f2add30590aa2b Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Mon, 8 Feb 2021 18:28:16 +0100 Subject: [PATCH] travis => github action --- .github/workflows/ci.yml | 52 +++++++++++++++++ .php_cs | 9 ++- .scrutinizer.yml | 24 -------- .travis.yml | 31 ---------- README.md | 3 +- composer.json | 24 ++++++-- infection.json.dist => infection.json | 2 +- phpinsights.php | 57 ------------------- src/Application.php | 5 +- src/ExceptionHandler.php | 2 - src/ExceptionHelper.php | 2 - src/Middleware/MiddlewareDispatcher.php | 4 -- .../MiddlewareDispatcherInterface.php | 4 -- src/Router/AuraRouter.php | 14 +---- src/Router/FastRouteRouter.php | 20 +------ src/Router/Group.php | 4 -- src/Router/Route.php | 6 -- src/Router/RouteInterface.php | 2 - src/Router/RouterException.php | 4 -- src/Router/RouterInterface.php | 11 +--- .../AuraRouterGuzzlehttpPsr7Test.php | 8 +-- .../Integration/AuraRouterNyholmPsr7Test.php | 8 +-- tests/Integration/AuraRouterSlimPsr7Test.php | 8 +-- .../AuraRouterZendDiactorosTest.php | 8 +-- .../FastRouteGuzzlehttpPsr7Test.php | 8 +-- tests/Integration/FastRouteNyholmPsr7Test.php | 8 +-- tests/Integration/FastRouteSlimPsr7Test.php | 8 +-- .../FastRouteZendDiactorosTest.php | 8 +-- tests/Unit/ApplicationTest.php | 17 ++---- tests/Unit/ExceptionHandlerTest.php | 6 +- .../Middleware/MiddlewareDispatcherTest.php | 4 +- .../MiddlewareRequestHandlerTest.php | 2 +- .../CallbackRequestHandlerTest.php | 2 +- tests/Unit/Router/AuraRouterTest.php | 4 +- 34 files changed, 134 insertions(+), 245 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml rename infection.json.dist => infection.json (74%) delete mode 100644 phpinsights.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..be34906 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: + push: + +jobs: + php72-min: + name: PHP 7.2 (--prefer-lowest) + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php72:latest + env: + COMPOSER_ARGS: "--prefer-lowest" + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + php72: + name: PHP 7.2 + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php72:latest + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + php73-min: + name: PHP 7.3 (--prefer-lowest) + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php73:latest + env: + COMPOSER_ARGS: "--prefer-lowest" + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + php73: + name: PHP 7.3 + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php73:latest + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.php_cs b/.php_cs index d339e1b..65bdd31 100644 --- a/.php_cs +++ b/.php_cs @@ -20,18 +20,23 @@ return PhpCsFixer\Config::create() 'final_class' => true, 'is_null' => true, 'linebreak_after_opening_tag' => true, - 'list_syntax' => true, + 'list_syntax' => ['syntax' => 'short'], 'method_chaining_indentation' => false, 'no_php4_constructor' => true, 'ordered_interfaces' => true, - 'php_unit_dedicate_assert' => true, 'php_unit_dedicate_assert_internal_type' => true, + 'php_unit_dedicate_assert' => true, 'php_unit_expectation' => true, 'php_unit_mock' => true, 'php_unit_namespaced' => true, 'php_unit_no_expectation_annotation' => true, + 'phpdoc_to_comment' => false, + 'single_line_throw' => false, + 'static_lambda' => true, 'ternary_to_null_coalescing' => true, + 'use_arrow_functions' => false, 'void_return' => true, + 'yoda_style' => true, ]) ->setRiskyAllowed(true) ->setFinder($finder) diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 59a043b..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,24 +0,0 @@ -build: - environment: - timezone: 'Europe/Zurich' - php: - version: '7.2' - ini: - 'date.timezone': 'Europe/Zurich' - tests: - override: - - - command: 'vendor/bin/phpunit --coverage-clover=coverage/clover.xml' - coverage: - file: 'coverage/clover.xml' - format: 'php-clover' - -checks: - php: true - -coding_style: - php: {} - -filter: - excluded_paths: - - 'tests/*' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0e5f8c4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: php - -matrix: - include: - - php: 7.2 - env: dependencies=lowest - - php: 7.2 - env: dependencies=highest - - php: 7.3 - env: dependencies=lowest - - php: 7.3 - env: dependencies=highest - -before_script: - - echo 'Europe/Zurich' | sudo tee /etc/timezone - - echo 'date.timezone = "Europe/Zurich"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - composer self-update -q - - if [ -z "$dependencies" ]; then composer install; fi; - - if [ "$dependencies" = "highest" ]; then composer update -n; fi; - - if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest -n; fi; - -script: - - vendor/bin/phpunit --coverage-text --verbose - - vendor/bin/infection --threads=$(nproc) --min-msi=100 --min-covered-msi=100 --verbose - - vendor/bin/phpstan analyse - - vendor/bin/phploc src --verbose - - vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation - - if [ -z "$dependencies" ]; then vendor/bin/phpinsights analyse --no-interaction --min-quality=97; fi; - - if [ "$dependencies" = "highest" ]; then vendor/bin/phpinsights analyse --no-interaction --min-quality=97; fi; - - if [ "$dependencies" = "lowest" ]; then vendor/bin/phpinsights analyse --no-interaction --min-quality=97 --disable-security-check; fi; - diff --git a/README.md b/README.md index a2ea1ad..2a1f52e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # chubbyphp-framework -[![Build Status](https://api.travis-ci.org/chubbyphp/chubbyphp-framework.png?branch=master)](https://travis-ci.org/chubbyphp/chubbyphp-framework) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-framework/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-framework/?branch=master) +[![CI](https://github.com/chubbyphp/chubbyphp-framework/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyphp/chubbyphp-framework/actions?query=workflow%3ACI) [![Code Coverage](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-framework/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/chubbyphp/chubbyphp-framework/?branch=master) [![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-framework/downloads.png)](https://packagist.org/packages/chubbyphp/chubbyphp-framework) [![Monthly Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-framework/d/monthly)](https://packagist.org/packages/chubbyphp/chubbyphp-framework) diff --git a/composer.json b/composer.json index ee8009f..5c8fd47 100644 --- a/composer.json +++ b/composer.json @@ -33,16 +33,17 @@ "require-dev": { "aura/router": "^3.1", "chubbyphp/chubbyphp-mock": "^1.4", - "friendsofphp/php-cs-fixer": "^2.15.1", + "friendsofphp/php-cs-fixer": "^2.18.2", "guzzlehttp/psr7": "^1.4.2", "http-interop/http-factory-guzzle": "^1.0", "infection/infection": "^0.13.4", "nikic/fast-route": "^1.3", "nunomaduro/phpinsights": "^1.7", "nyholm/psr7": "^1.0", - "phploc/phploc": "^5.0", - "phpstan/phpstan": "^0.11.12", - "phpunit/phpunit": "^8.3.3", + "php-coveralls/php-coveralls": "^2.4.3", + "phploc/phploc": "^5.0|^6.0.2", + "phpstan/phpstan": "^0.11.20", + "phpunit/phpunit": "^8.5.14", "slim/psr7": "^0.5", "zendframework/zend-diactoros": "^2.0" }, @@ -56,5 +57,20 @@ "branch-alias": { "dev-master": "1.2-dev" } + }, + "scripts": { + "fix:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --cache-file=build/phpcs.cache", + "test": [ + "@test:phpunit", + "@test:infection", + "@test:static-analysis", + "@test:loc", + "@test:cs" + ], + "test:cs": "mkdir -p build && 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 --min-covered-msi=100 --verbose", + "test:loc": "vendor/bin/phploc src --verbose", + "test:phpunit": "vendor/bin/phpunit --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", + "test:static-analysis": "vendor/bin/phpstan analyse" } } diff --git a/infection.json.dist b/infection.json similarity index 74% rename from infection.json.dist rename to infection.json index 5d6c56f..3ac65e1 100644 --- a/infection.json.dist +++ b/infection.json @@ -6,6 +6,6 @@ }, "timeout": 10, "logs": { - "text": "infectionlog.txt" + "text": "build/infectionlog.txt" } } diff --git a/phpinsights.php b/phpinsights.php deleted file mode 100644 index 872ef1c..0000000 --- a/phpinsights.php +++ /dev/null @@ -1,57 +0,0 @@ - 'default', - 'exclude' => [], - 'add' => [], - 'remove' => [ - AssignmentInConditionSniff::class, - DisallowYodaComparisonSniff::class, - SpaceAfterNotSniff::class, - SuperfluousAbstractClassNamingSniff::class, - SuperfluousExceptionNamingSniff::class, - SuperfluousInterfaceNamingSniff::class, - SuperfluousTraitNamingSniff::class, - UnnecessaryStringConcatSniff::class, - UselessOverridingMethodSniff::class, // cause visibility change on expections __construct, - ], - 'config' => [ - CyclomaticComplexityIsHigh::class => [ - 'maxComplexity' => 15, - ], - FunctionLengthSniff::class => [ - 'maxLength' => 30, - ], - LineLengthSniff::class => [ - 'lineLimit' => 120, - 'absoluteLineLimit' => 120, - ], - MaxNestingLevelSniff::class => [ - 'maxNestingLevel' => 5, - ], - MethodPerClassLimitSniff::class => [ - 'maxCount' => 20, - ], - UnusedUsesSniff::class => [ - 'searchAnnotations' => true, - ], - ], -]; diff --git a/src/Application.php b/src/Application.php index d47fa88..62233e4 100644 --- a/src/Application.php +++ b/src/Application.php @@ -36,10 +36,7 @@ final class Application implements RequestHandlerInterface private $middlewares; /** - * @param RouterInterface $router - * @param MiddlewareDispatcherInterface $middlewareDispatcher - * @param ExceptionHandlerInterface $exceptionHandler - * @param array $middlewares + * @param array $middlewares */ public function __construct( RouterInterface $router, diff --git a/src/ExceptionHandler.php b/src/ExceptionHandler.php index 2dfd7e6..413e51f 100644 --- a/src/ExceptionHandler.php +++ b/src/ExceptionHandler.php @@ -131,8 +131,6 @@ public function createExceptionResponse(ServerRequestInterface $request, \Throwa /** * @param array> $exceptionsData - * - * @return string */ private function addDebugToHtml(array $exceptionsData): string { diff --git a/src/ExceptionHelper.php b/src/ExceptionHelper.php index a7ff52a..1c05b1e 100644 --- a/src/ExceptionHelper.php +++ b/src/ExceptionHelper.php @@ -7,8 +7,6 @@ final class ExceptionHelper { /** - * @param \Throwable $exception - * * @return array> */ public static function toArray(\Throwable $exception): array diff --git a/src/Middleware/MiddlewareDispatcher.php b/src/Middleware/MiddlewareDispatcher.php index 21df3d1..9ee8bf8 100644 --- a/src/Middleware/MiddlewareDispatcher.php +++ b/src/Middleware/MiddlewareDispatcher.php @@ -13,10 +13,6 @@ final class MiddlewareDispatcher implements MiddlewareDispatcherInterface { /** * @param array $middlewares - * @param RequestHandlerInterface $handler - * @param ServerRequestInterface $request - * - * @return ResponseInterface */ public function dispatch( array $middlewares, diff --git a/src/Middleware/MiddlewareDispatcherInterface.php b/src/Middleware/MiddlewareDispatcherInterface.php index 6141caf..be5d9bd 100644 --- a/src/Middleware/MiddlewareDispatcherInterface.php +++ b/src/Middleware/MiddlewareDispatcherInterface.php @@ -13,10 +13,6 @@ interface MiddlewareDispatcherInterface { /** * @param array $middlewares - * @param RequestHandlerInterface $handler - * @param ServerRequestInterface $request - * - * @return ResponseInterface */ public function dispatch( array $middlewares, diff --git a/src/Router/AuraRouter.php b/src/Router/AuraRouter.php index 09ae88e..f821da3 100644 --- a/src/Router/AuraRouter.php +++ b/src/Router/AuraRouter.php @@ -35,7 +35,6 @@ final class AuraRouter implements RouterInterface /** * @param array $routes - * @param string $basePath */ public function __construct(array $routes, string $basePath = '') { @@ -71,14 +70,10 @@ public function match(ServerRequestInterface $request): RouteInterface } /** - * @param ServerRequestInterface $request - * @param string $name - * @param array $attributes - * @param array $queryParams + * @param array $attributes + * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generateUrl( ServerRequestInterface $request, @@ -93,13 +88,10 @@ public function generateUrl( } /** - * @param string $name * @param array $attributes * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generatePath(string $name, array $attributes = [], array $queryParams = []): string { @@ -133,8 +125,6 @@ private function getRoutesByName(array $routes): array /** * @param array $routes - * - * @return RouterContainer */ private function getRouterContainer(array $routes): RouterContainer { diff --git a/src/Router/FastRouteRouter.php b/src/Router/FastRouteRouter.php index 3c48447..a0e85d0 100644 --- a/src/Router/FastRouteRouter.php +++ b/src/Router/FastRouteRouter.php @@ -34,8 +34,6 @@ final class FastRouteRouter implements RouterInterface /** * @param array $routes - * @param string|null $cacheFile - * @param string $basePath */ public function __construct(array $routes, ?string $cacheFile = null, string $basePath = '') { @@ -71,14 +69,10 @@ public function match(ServerRequestInterface $request): RouteInterface } /** - * @param ServerRequestInterface $request - * @param string $name - * @param array $attributes - * @param array $queryParams + * @param array $attributes + * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generateUrl( ServerRequestInterface $request, @@ -93,13 +87,10 @@ public function generateUrl( } /** - * @param string $name * @param array $attributes * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generatePath(string $name, array $attributes = [], array $queryParams = []): string { @@ -144,9 +135,6 @@ private function getRoutesByName(array $routes): array /** * @param array $routes - * @param string|null $cacheFile - * - * @return Dispatcher */ private function getDispatcher(array $routes, ?string $cacheFile = null): Dispatcher { @@ -166,8 +154,6 @@ private function getDispatcher(array $routes, ?string $cacheFile = null): Dispat /** * @param array $routes - * - * @return RouteCollector */ private function getRouteCollector(array $routes): RouteCollector { @@ -191,8 +177,6 @@ private function getRoute(string $name): RouteInterface /** * @param array> $routePartSets * @param array $attributes - * - * @return int */ private function getRouteIndex(array $routePartSets, array $attributes): int { diff --git a/src/Router/Group.php b/src/Router/Group.php index 375a60d..fe089ed 100644 --- a/src/Router/Group.php +++ b/src/Router/Group.php @@ -40,8 +40,6 @@ public static function create(string $path): self /** * @param array $pathOptions - * - * @return self */ public function pathOptions(array $pathOptions): self { @@ -52,8 +50,6 @@ public function pathOptions(array $pathOptions): self /** * @param array $middlewares - * - * @return self */ public function middlewares(array $middlewares): self { diff --git a/src/Router/Route.php b/src/Router/Route.php index d3b2f91..ca80265 100644 --- a/src/Router/Route.php +++ b/src/Router/Route.php @@ -98,8 +98,6 @@ public static function put(string $path, string $name, RequestHandlerInterface $ /** * @param array $pathOptions - * - * @return self */ public function pathOptions(array $pathOptions): self { @@ -110,8 +108,6 @@ public function pathOptions(array $pathOptions): self /** * @param array $middlewares - * - * @return self */ public function middlewares(array $middlewares): self { @@ -167,8 +163,6 @@ public function getRequestHandler(): RequestHandlerInterface /** * @param array $attributes - * - * @return RouteInterface */ public function withAttributes(array $attributes): RouteInterface { diff --git a/src/Router/RouteInterface.php b/src/Router/RouteInterface.php index ba9c4d5..d46d088 100644 --- a/src/Router/RouteInterface.php +++ b/src/Router/RouteInterface.php @@ -37,8 +37,6 @@ public function getRequestHandler(): RequestHandlerInterface; /** * @param array $attributes - * - * @return RouteInterface */ public function withAttributes(array $attributes): RouteInterface; diff --git a/src/Router/RouterException.php b/src/Router/RouterException.php index 55b5771..adc54b4 100644 --- a/src/Router/RouterException.php +++ b/src/Router/RouterException.php @@ -35,11 +35,7 @@ public static function createForNotFound(string $path): self } /** - * @param string $method * @param array $methods - * @param string $path - * - * @return self */ public static function createForMethodNotAllowed(string $method, array $methods, string $path): self { diff --git a/src/Router/RouterInterface.php b/src/Router/RouterInterface.php index a6fab15..ace9829 100644 --- a/src/Router/RouterInterface.php +++ b/src/Router/RouterInterface.php @@ -11,14 +11,10 @@ interface RouterInterface public function match(ServerRequestInterface $request): RouteInterface; /** - * @param ServerRequestInterface $request - * @param string $name - * @param array $attributes - * @param array $queryParams + * @param array $attributes + * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generateUrl( ServerRequestInterface $request, @@ -28,13 +24,10 @@ public function generateUrl( ): string; /** - * @param string $name * @param array $attributes * @param array $queryParams * * @throws RouterException - * - * @return string */ public function generatePath(string $name, array $attributes = [], array $queryParams = []): string; } diff --git a/tests/Integration/AuraRouterGuzzlehttpPsr7Test.php b/tests/Integration/AuraRouterGuzzlehttpPsr7Test.php index b97df1d..993c61a 100644 --- a/tests/Integration/AuraRouterGuzzlehttpPsr7Test.php +++ b/tests/Integration/AuraRouterGuzzlehttpPsr7Test.php @@ -28,7 +28,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -59,7 +59,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -93,7 +93,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -127,7 +127,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); diff --git a/tests/Integration/AuraRouterNyholmPsr7Test.php b/tests/Integration/AuraRouterNyholmPsr7Test.php index cdf7b64..37b665b 100644 --- a/tests/Integration/AuraRouterNyholmPsr7Test.php +++ b/tests/Integration/AuraRouterNyholmPsr7Test.php @@ -28,7 +28,7 @@ public function testOk(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -59,7 +59,7 @@ public function testTestNotFound(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -93,7 +93,7 @@ public function testMethodNotAllowed(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -127,7 +127,7 @@ public function testException(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); diff --git a/tests/Integration/AuraRouterSlimPsr7Test.php b/tests/Integration/AuraRouterSlimPsr7Test.php index 447ea27..a1956d5 100644 --- a/tests/Integration/AuraRouterSlimPsr7Test.php +++ b/tests/Integration/AuraRouterSlimPsr7Test.php @@ -31,7 +31,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -66,7 +66,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -104,7 +104,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -142,7 +142,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); diff --git a/tests/Integration/AuraRouterZendDiactorosTest.php b/tests/Integration/AuraRouterZendDiactorosTest.php index 34db28a..daa58e6 100644 --- a/tests/Integration/AuraRouterZendDiactorosTest.php +++ b/tests/Integration/AuraRouterZendDiactorosTest.php @@ -28,7 +28,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -62,7 +62,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -99,7 +99,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -136,7 +136,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); diff --git a/tests/Integration/FastRouteGuzzlehttpPsr7Test.php b/tests/Integration/FastRouteGuzzlehttpPsr7Test.php index 3f40bb7..eb119cc 100644 --- a/tests/Integration/FastRouteGuzzlehttpPsr7Test.php +++ b/tests/Integration/FastRouteGuzzlehttpPsr7Test.php @@ -28,7 +28,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -59,7 +59,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -93,7 +93,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -127,7 +127,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); diff --git a/tests/Integration/FastRouteNyholmPsr7Test.php b/tests/Integration/FastRouteNyholmPsr7Test.php index 7936860..dedf65d 100644 --- a/tests/Integration/FastRouteNyholmPsr7Test.php +++ b/tests/Integration/FastRouteNyholmPsr7Test.php @@ -28,7 +28,7 @@ public function testOk(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -59,7 +59,7 @@ public function testTestNotFound(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -93,7 +93,7 @@ public function testMethodNotAllowed(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($psr17Factory) { + static function (ServerRequestInterface $request) use ($psr17Factory) { $name = $request->getAttribute('name'); $response = $psr17Factory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -127,7 +127,7 @@ public function testException(): void $psr17Factory = new Psr17Factory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); diff --git a/tests/Integration/FastRouteSlimPsr7Test.php b/tests/Integration/FastRouteSlimPsr7Test.php index 85129a0..904d401 100644 --- a/tests/Integration/FastRouteSlimPsr7Test.php +++ b/tests/Integration/FastRouteSlimPsr7Test.php @@ -31,7 +31,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -66,7 +66,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -104,7 +104,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -142,7 +142,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); diff --git a/tests/Integration/FastRouteZendDiactorosTest.php b/tests/Integration/FastRouteZendDiactorosTest.php index 4c60de0..c5d6804 100644 --- a/tests/Integration/FastRouteZendDiactorosTest.php +++ b/tests/Integration/FastRouteZendDiactorosTest.php @@ -28,7 +28,7 @@ public function testOk(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -62,7 +62,7 @@ public function testTestNotFound(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -99,7 +99,7 @@ public function testMethodNotAllowed(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (ServerRequestInterface $request) use ($responseFactory) { + static function (ServerRequestInterface $request) use ($responseFactory) { $name = $request->getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -136,7 +136,7 @@ public function testException(): void $responseFactory = new ResponseFactory(); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index d974e0e..8640975 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -12,9 +12,7 @@ final class TestHeader private static $headers = []; /** - * @param string $header - * @param bool $replace - * @param int $http_response_code + * @param int $http_response_code */ public static function add(string $header, bool $replace = true, int $http_response_code = null): void { @@ -25,9 +23,6 @@ public static function add(string $header, bool $replace = true, int $http_respo ]; } - /** - * @return array - */ public static function all(): array { return self::$headers; @@ -40,9 +35,7 @@ public static function reset(): void } /** - * @param string $header - * @param bool $replace - * @param int $http_response_code + * @param int $http_response_code */ function header(string $header, bool $replace = true, int $http_response_code = null): void { @@ -163,7 +156,7 @@ public function testHandleWithMiddlewares(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request @@ -243,7 +236,7 @@ public function testHandleRouterExceptionWithMiddlewares(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request @@ -360,7 +353,7 @@ public function testHandleThrowableWithMiddlewares(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request diff --git a/tests/Unit/ExceptionHandlerTest.php b/tests/Unit/ExceptionHandlerTest.php index e0dfb09..0ba04ba 100644 --- a/tests/Unit/ExceptionHandlerTest.php +++ b/tests/Unit/ExceptionHandlerTest.php @@ -247,7 +247,7 @@ public function testCreateExceptionResponse(): void $logger = $this->getMockByCalls(LoggerInterface::class, [ Call::create('error')->with( 'Exception', - new ArgumentCallback(function (array $context): void { + new ArgumentCallback(static function (array $context): void { self::assertArrayHasKey('exceptions', $context); $exceptions = $context['exceptions']; @@ -362,7 +362,7 @@ public function testCreateExceptionResponseInDebugMode(): void /** @var StreamInterface|MockObject $responseBody */ $responseBody = $this->getMockByCalls(StreamInterface::class, [ Call::create('write') - ->with(new ArgumentCallback(function (string $html): void { + ->with(new ArgumentCallback(static function (string $html): void { self::assertStringContainsString( 'A website error has occurred. Sorry for the temporary inconvenience.', $html @@ -401,7 +401,7 @@ public function testCreateExceptionResponseInDebugMode(): void $logger = $this->getMockByCalls(LoggerInterface::class, [ Call::create('error')->with( 'Exception', - new ArgumentCallback(function (array $context): void { + new ArgumentCallback(static function (array $context): void { self::assertArrayHasKey('exceptions', $context); $exceptions = $context['exceptions']; diff --git a/tests/Unit/Middleware/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/MiddlewareDispatcherTest.php index 51b652d..dd130f7 100644 --- a/tests/Unit/Middleware/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/MiddlewareDispatcherTest.php @@ -64,7 +64,7 @@ public function testWithMiddlewares(): void Call::create('process') ->with($request, new ArgumentInstanceOf(MiddlewareRequestHandler::class)) ->willReturnCallback( - function (ServerRequestInterface $request, RequestHandlerInterface $handler) { + static function (ServerRequestInterface $request, RequestHandlerInterface $handler) { $request->withAttribute('middleware', 1); return $handler->handle($request); @@ -77,7 +77,7 @@ function (ServerRequestInterface $request, RequestHandlerInterface $handler) { Call::create('process') ->with($request, $handler) ->willReturnCallback( - function (ServerRequestInterface $request, RequestHandlerInterface $handler) { + static function (ServerRequestInterface $request, RequestHandlerInterface $handler) { $request->withAttribute('middleware', 2); return $handler->handle($request); diff --git a/tests/Unit/Middleware/MiddlewareRequestHandlerTest.php b/tests/Unit/Middleware/MiddlewareRequestHandlerTest.php index cf0c879..04fe2d9 100644 --- a/tests/Unit/Middleware/MiddlewareRequestHandlerTest.php +++ b/tests/Unit/Middleware/MiddlewareRequestHandlerTest.php @@ -40,7 +40,7 @@ public function testHandle(): void $middleware = $this->getMockByCalls(MiddlewareInterface::class, [ Call::create('process') ->with($request, $handler) - ->willReturnCallback(function (ServerRequestInterface $request, RequestHandlerInterface $handler) { + ->willReturnCallback(static function (ServerRequestInterface $request, RequestHandlerInterface $handler) { return $handler->handle($request); }), ]); diff --git a/tests/Unit/RequestHandler/CallbackRequestHandlerTest.php b/tests/Unit/RequestHandler/CallbackRequestHandlerTest.php index 7daf0cc..4ae7148 100644 --- a/tests/Unit/RequestHandler/CallbackRequestHandlerTest.php +++ b/tests/Unit/RequestHandler/CallbackRequestHandlerTest.php @@ -28,7 +28,7 @@ public function testHandle(): void /** @var ResponseInterface|MockObject $response */ $response = $this->getMockByCalls(ResponseInterface::class); - $callbackRequestHandler = new CallbackRequestHandler(function (ServerRequestInterface $request) use ($response) { + $callbackRequestHandler = new CallbackRequestHandler(static function (ServerRequestInterface $request) use ($response) { return $response; }); diff --git a/tests/Unit/Router/AuraRouterTest.php b/tests/Unit/Router/AuraRouterTest.php index 9d66e51..cde8b24 100644 --- a/tests/Unit/Router/AuraRouterTest.php +++ b/tests/Unit/Router/AuraRouterTest.php @@ -379,7 +379,7 @@ public function testMatchWithSpecialMatch(): void $route = $this->getMockByCalls(RouteInterface::class, [ Call::create('getName')->with()->willReturn('index'), Call::create('getPathOptions')->with() - ->willReturn(['special' => function (ServerRequestInterface $request, Route $route) { + ->willReturn(['special' => static function (ServerRequestInterface $request, Route $route) { return true; }]), Call::create('getName')->with()->willReturn('index'), @@ -420,7 +420,7 @@ public function testMatchWithSpecialNotMatch(): void $route = $this->getMockByCalls(RouteInterface::class, [ Call::create('getName')->with()->willReturn('index'), Call::create('getPathOptions')->with() - ->willReturn(['special' => function (ServerRequestInterface $request, Route $route) { + ->willReturn(['special' => static function (ServerRequestInterface $request, Route $route) { return false; }]), Call::create('getName')->with()->willReturn('index'),