From 9d137a0c9a6105a931a2b72a4d0437887ba01a2c Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Mon, 8 Feb 2021 20:56:22 +0100 Subject: [PATCH] travis => github action --- .github/workflows/ci.yml | 75 +++++++++++++++++++ .php_cs | 40 +++++++--- .travis.yml | 28 ------- README.md | 2 +- composer.json | 24 +++--- phpinsights.php | 8 -- phpstan.neon | 3 + tests/Integration/AuraRouterTest.php | 12 +-- tests/Integration/FastRouteRouterTest.php | 12 +-- tests/Integration/SunriseRouterTest.php | 12 +-- tests/Integration/SymfonyRouterTest.php | 12 +-- tests/Unit/ApplicationTest.php | 6 +- tests/Unit/ErrorHandlerTest.php | 4 +- .../Middleware/CallbackMiddlewareTest.php | 2 +- .../Middleware/ExceptionMiddlewareTest.php | 8 +- .../Middleware/MiddlewareDispatcherTest.php | 4 +- .../MiddlewareRequestHandlerTest.php | 2 +- .../CallbackRequestHandlerTest.php | 2 +- tests/Unit/Router/AuraRouterTest.php | 4 +- tests/Unit/Router/SunriseRouterTest.php | 10 +++ 20 files changed, 170 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 phpinsights.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4c019f8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +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 }} + php74-min: + name: PHP 7.4 (--prefer-lowest) + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php74:latest + env: + COMPOSER_ARGS: "--prefer-lowest" + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + php74: + name: PHP 7.4 + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: composer test + uses: docker://chubbyphp/ci-php74: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 0469f19..5913b4d 100644 --- a/.php_cs +++ b/.php_cs @@ -9,15 +9,37 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . '/tests') ; -/** @var array $config */ -$config = require __DIR__ . '/vendor/chubbyphp/chubbyphp-dev-helper/phpcs.php'; - -unset ($config['rules']['final_class']); - return PhpCsFixer\Config::create() - ->setIndent($config['indent']) - ->setLineEnding($config['lineEnding']) - ->setRules($config['rules']) - ->setRiskyAllowed($config['riskyAllowed']) + ->setIndent(" ") + ->setLineEnding("\n") + ->setRules([ + '@DoctrineAnnotation' => true, + '@PhpCsFixer' => true, + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'declare_strict_types' => true, + 'dir_constant' => true, + 'final_class' => false, + 'is_null' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => ['syntax' => 'short'], + 'method_chaining_indentation' => false, + 'no_php4_constructor' => true, + 'ordered_interfaces' => 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/.travis.yml b/.travis.yml deleted file mode 100644 index 5a39518..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: php - -matrix: - include: - - php: 7.2 - env: dependencies=lowest - - php: 7.2 - - php: 7.3 - env: dependencies=lowest - - php: 7.3 - - php: 7.4 - env: dependencies=lowest - - php: 7.4 - -before_script: - - echo 'extension=apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/apcu.ini - - 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 - - composer global require hirak/prestissimo - - if [ -z "$dependencies" ]; then composer update -n; fi; - - if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest -n; fi; - -script: - - composer test - -after_success: - - travis_retry php vendor/bin/php-coveralls --coverage_clover=build/phpunit/phpunit.clover.xml --json_path=build/coveralls.json -v diff --git a/README.md b/README.md index 8b1416c..3bf6239 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # chubbyphp-framework -[![Build Status](https://api.travis-ci.org/chubbyphp/chubbyphp-framework.png?branch=master)](https://travis-ci.org/chubbyphp/chubbyphp-framework) +[![CI](https://github.com/chubbyphp/chubbyphp-framework/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyphp/chubbyphp-framework/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyphp/chubbyphp-framework/badge.svg?branch=master)](https://coveralls.io/github/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 7174523..1c8147e 100644 --- a/composer.json +++ b/composer.json @@ -33,23 +33,21 @@ "require-dev": { "aura/router": "^3.1", "bittyphp/http": "^2.0", - "chubbyphp/chubbyphp-dev-helper": "dev-master", "chubbyphp/chubbyphp-mock": "^1.4.5", + "friendsofphp/php-cs-fixer": "^2.18.2", "guzzlehttp/psr7": "^1.4.2", "http-interop/http-factory-guzzle": "^1.0", - "infection/infection": "^0.15.3|^0.16.2", + "infection/infection": "^0.13.4", "laminas/laminas-diactoros": "^2.0", - "mavimo/phpstan-junit": "^0.3", "nikic/fast-route": "^1.0|^0.6", "nyholm/psr7": "^1.0", - "php-coveralls/php-coveralls": "^2.2", - "phploc/phploc": "^5.0|^6.0.", - "phpstan/extension-installer": "^1.0.4", - "phpstan/phpstan": "^0.12.19", - "phpunit/phpunit": "^8.5.3|^9.1.1", + "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|^1.0", "sunrise/http-factory": "^1.0.4", - "sunrise/http-router": "^2.4", + "sunrise/http-router": "^2.6", "symfony/expression-language": "^4.3|^5.0", "symfony/routing": "^4.3|^5.0" }, @@ -76,16 +74,14 @@ "@test:infection", "@test:static-analysis", "@test:loc", - "@test:cs", - "@test:insights" + "@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 --verbose --coverage=build/phpunit", - "test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=97 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'", "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 --verbose | tee build/phploc.log", - "test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=7 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'", - "test:unit": "phpdbg -qrr 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" + "test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress | tee build/phpstan.txt; 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/phpunit.junit.xml --cache-result-file=build/phpunit/result.cache" } } diff --git a/phpinsights.php b/phpinsights.php deleted file mode 100644 index d41f513..0000000 --- a/phpinsights.php +++ /dev/null @@ -1,8 +0,0 @@ -getAttribute('name'); $response = $responseFactory->createResponse(); $response->getBody()->write(sprintf('Hello, %s', $name)); @@ -106,7 +106,7 @@ public function testTestNotFound( ServerRequestFactoryInterface $serverRequestFactory ): void { $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 testMethodNotAllowed( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -178,7 +178,7 @@ public function testException( ServerRequestFactoryInterface $serverRequestFactory ): void { $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); @@ -214,7 +214,7 @@ public function testExceptionWithoutExceptionMiddleware( $this->expectExceptionMessage('Something went wrong'); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); @@ -234,7 +234,7 @@ function (): void { public function testGeneratePath(): void { $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void {} + static function (): void {} ))->pathOptions(['tokens' => ['name' => '[a-z]+']]); $router = new AuraRouter([$route]); diff --git a/tests/Integration/FastRouteRouterTest.php b/tests/Integration/FastRouteRouterTest.php index b754e12..8f27b44 100644 --- a/tests/Integration/FastRouteRouterTest.php +++ b/tests/Integration/FastRouteRouterTest.php @@ -73,7 +73,7 @@ public function testOk( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -106,7 +106,7 @@ public function testTestNotFound( ServerRequestFactoryInterface $serverRequestFactory ): void { $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 testMethodNotAllowed( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -178,7 +178,7 @@ public function testException( ServerRequestFactoryInterface $serverRequestFactory ): void { $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); @@ -214,7 +214,7 @@ public function testExceptionWithoutExceptionMiddleware( $this->expectExceptionMessage('Something went wrong'); $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); @@ -234,7 +234,7 @@ function (): void { public function testGeneratePath(): void { $route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler( - function (): void {} + static function (): void {} )); $router = new FastRouteRouter([$route]); diff --git a/tests/Integration/SunriseRouterTest.php b/tests/Integration/SunriseRouterTest.php index 8f03505..049b465 100644 --- a/tests/Integration/SunriseRouterTest.php +++ b/tests/Integration/SunriseRouterTest.php @@ -73,7 +73,7 @@ public function testOk( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -106,7 +106,7 @@ public function testTestNotFound( ServerRequestFactoryInterface $serverRequestFactory ): void { $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 testMethodNotAllowed( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -178,7 +178,7 @@ public function testException( ServerRequestFactoryInterface $serverRequestFactory ): void { $route = Route::get('/hello/{name<[a-z]+>}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); @@ -214,7 +214,7 @@ public function testExceptionWithoutExceptionMiddleware( $this->expectExceptionMessage('Something went wrong'); $route = Route::get('/hello/{name<[a-z]+>}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } )); @@ -234,7 +234,7 @@ function (): void { public function testGeneratePath(): void { $route = Route::get('/hello/{name<[a-z]+>}', 'hello', new CallbackRequestHandler( - function (): void {} + static function (): void {} )); $router = new SunriseRouter([$route]); diff --git a/tests/Integration/SymfonyRouterTest.php b/tests/Integration/SymfonyRouterTest.php index e213b39..f90fb90 100644 --- a/tests/Integration/SymfonyRouterTest.php +++ b/tests/Integration/SymfonyRouterTest.php @@ -73,7 +73,7 @@ public function testOk( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -106,7 +106,7 @@ public function testTestNotFound( ServerRequestFactoryInterface $serverRequestFactory ): void { $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 testMethodNotAllowed( ServerRequestFactoryInterface $serverRequestFactory ): void { $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)); @@ -178,7 +178,7 @@ public function testException( ServerRequestFactoryInterface $serverRequestFactory ): void { $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['requirements' => ['name' => '[a-z]+']]); @@ -214,7 +214,7 @@ public function testExceptionWithoutExceptionMiddleware( $this->expectExceptionMessage('Something went wrong'); $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void { + static function (): void { throw new \RuntimeException('Something went wrong'); } ))->pathOptions(['requirements' => ['name' => '[a-z]+']]); @@ -234,7 +234,7 @@ function (): void { public function testGeneratePath(): void { $route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler( - function (): void {} + static function (): void {} ))->pathOptions(['requirements' => ['name' => '[a-z]+']]); $router = new SymfonyRouter([$route]); diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index 51c6ecf..b1bc72b 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -57,7 +57,7 @@ public function testInvoke(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request @@ -106,7 +106,7 @@ public function testHandle(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request @@ -149,7 +149,7 @@ public function testHandleWithMissingRouteAttribute(): void $middlewareDispatcher = $this->getMockByCalls(MiddlewareDispatcherInterface::class, [ Call::create('dispatch') ->willReturnCallback( - function ( + static function ( array $middlewares, CallbackRequestHandler $requestHandler, ServerRequestInterface $request diff --git a/tests/Unit/ErrorHandlerTest.php b/tests/Unit/ErrorHandlerTest.php index 4b445bb..2728746 100644 --- a/tests/Unit/ErrorHandlerTest.php +++ b/tests/Unit/ErrorHandlerTest.php @@ -18,7 +18,7 @@ public function testRestoreErrorHandlerWithinConstruct(): void { $hasError = false; - set_error_handler(function () use (&$hasError): void { + set_error_handler(static function () use (&$hasError): void { $hasError = true; }); @@ -62,7 +62,7 @@ public function testErrorToException(): void $hasError = false; - set_error_handler(function () use (&$hasError): void { + set_error_handler(static function () use (&$hasError): void { $hasError = true; }); diff --git a/tests/Unit/Middleware/CallbackMiddlewareTest.php b/tests/Unit/Middleware/CallbackMiddlewareTest.php index 6c6f1bf..9de85e9 100644 --- a/tests/Unit/Middleware/CallbackMiddlewareTest.php +++ b/tests/Unit/Middleware/CallbackMiddlewareTest.php @@ -36,7 +36,7 @@ public function testHandle(): void ]); $callbackMiddleware = new CallbackMiddleware( - function (ServerRequestInterface $request, RequestHandlerInterface $handler) use ($response) { + static function (ServerRequestInterface $request, RequestHandlerInterface $handler) { return $handler->handle($request); } ); diff --git a/tests/Unit/Middleware/ExceptionMiddlewareTest.php b/tests/Unit/Middleware/ExceptionMiddlewareTest.php index c58c573..480a158 100644 --- a/tests/Unit/Middleware/ExceptionMiddlewareTest.php +++ b/tests/Unit/Middleware/ExceptionMiddlewareTest.php @@ -190,7 +190,7 @@ public function testProcessWithExceptionWithoutDebugWithLogger(): 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']; self::assertCount(2, $exceptions); @@ -231,7 +231,7 @@ public function testProcessWithExceptionWithDebugWithoutLogger(): 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 @@ -284,7 +284,7 @@ public function testProcessWithExceptionWithDebugWithLogger(): 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 @@ -326,7 +326,7 @@ public function testProcessWithExceptionWithDebugWithLogger(): 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']; self::assertCount(2, $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 06e90ee..b810f5a 100644 --- a/tests/Unit/Router/AuraRouterTest.php +++ b/tests/Unit/Router/AuraRouterTest.php @@ -393,7 +393,7 @@ public function testMatchWithSpecialMatch(): void $route = $this->getMockByCalls(RouteInterface::class, [ Call::create('getName')->with()->willReturn('index'), Call::create('getPathOptions')->with() - ->willReturn([AuraRouter::PATH_SPECIAL => function (ServerRequestInterface $request, Route $route) { + ->willReturn([AuraRouter::PATH_SPECIAL => static function (ServerRequestInterface $request, Route $route) { return true; }]), Call::create('getName')->with()->willReturn('index'), @@ -434,7 +434,7 @@ public function testMatchWithSpecialNotMatch(): void $route = $this->getMockByCalls(RouteInterface::class, [ Call::create('getName')->with()->willReturn('index'), Call::create('getPathOptions')->with() - ->willReturn([AuraRouter::PATH_SPECIAL => function (ServerRequestInterface $request, Route $route) { + ->willReturn([AuraRouter::PATH_SPECIAL => static function (ServerRequestInterface $request, Route $route) { return false; }]), Call::create('getName')->with()->willReturn('index'), diff --git a/tests/Unit/Router/SunriseRouterTest.php b/tests/Unit/Router/SunriseRouterTest.php index 4434904..c1fcb46 100644 --- a/tests/Unit/Router/SunriseRouterTest.php +++ b/tests/Unit/Router/SunriseRouterTest.php @@ -31,11 +31,13 @@ public function testMatchFound(): void { /** @var UriInterface|MockObject $uri */ $uri = $this->getMockByCalls(UriInterface::class, [ + Call::create('getHost')->with()->willReturn('localhost'), Call::create('getPath')->with()->willReturn('/api/pets'), ]); /** @var ServerRequestInterface|MockObject $request */ $request = $this->getMockByCalls(ServerRequestInterface::class, [ + Call::create('getUri')->with()->willReturn($uri), Call::create('getUri')->with()->willReturn($uri), Call::create('getMethod')->with()->willReturn('GET'), Call::create('getMethod')->with()->willReturn('GET'), @@ -90,11 +92,13 @@ public function testMatchNotFound(): void /** @var UriInterface|MockObject $uri */ $uri = $this->getMockByCalls(UriInterface::class, [ + Call::create('getHost')->with()->willReturn('localhost'), Call::create('getPath')->with()->willReturn('/'), ]); /** @var ServerRequestInterface|MockObject $request */ $request = $this->getMockByCalls(ServerRequestInterface::class, [ + Call::create('getUri')->with()->willReturn($uri), Call::create('getUri')->with()->willReturn($uri), Call::create('getMethod')->with()->willReturn('GET'), Call::create('getRequestTarget')->with()->willReturn('/'), @@ -130,11 +134,13 @@ public function testMatchMethodNotAllowed(): void /** @var UriInterface|MockObject $uri */ $uri = $this->getMockByCalls(UriInterface::class, [ + Call::create('getHost')->with()->willReturn('localhost'), Call::create('getPath')->with()->willReturn('/api/pets'), ]); /** @var ServerRequestInterface|MockObject $request */ $request = $this->getMockByCalls(ServerRequestInterface::class, [ + Call::create('getUri')->with()->willReturn($uri), Call::create('getUri')->with()->willReturn($uri), Call::create('getMethod')->with()->willReturn('POST'), Call::create('getRequestTarget')->with()->willReturn('/api/pets?offset=1&limit=20'), @@ -173,11 +179,13 @@ public function testMatchWithTokensNotMatch(): void /** @var UriInterface|MockObject $uri */ $uri = $this->getMockByCalls(UriInterface::class, [ + Call::create('getHost')->with()->willReturn('localhost'), Call::create('getPath')->with()->willReturn('/api/pets/1'), ]); /** @var ServerRequestInterface|MockObject $request */ $request = $this->getMockByCalls(ServerRequestInterface::class, [ + Call::create('getUri')->with()->willReturn($uri), Call::create('getUri')->with()->willReturn($uri), Call::create('getMethod')->with()->willReturn('GET'), Call::create('getRequestTarget')->with()->willReturn('/api/pets/1'), @@ -207,11 +215,13 @@ public function testMatchWithTokensMatch(): void { /** @var UriInterface|MockObject $uri */ $uri = $this->getMockByCalls(UriInterface::class, [ + Call::create('getHost')->with()->willReturn('localhost'), Call::create('getPath')->with()->willReturn('/api/pets/8b72750c-5306-416c-bba7-5b41f1c44791'), ]); /** @var ServerRequestInterface|MockObject $request */ $request = $this->getMockByCalls(ServerRequestInterface::class, [ + Call::create('getUri')->with()->willReturn($uri), Call::create('getUri')->with()->willReturn($uri), Call::create('getMethod')->with()->willReturn('GET'), Call::create('getMethod')->with()->willReturn('GET'),