From 425ac50ce7f75be9ef2c7d5a6b592383d4672304 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 19 Sep 2018 14:24:44 -0700 Subject: [PATCH 1/9] Add PATCH support (#87) --- CHANGELOG.md | 7 +++++++ src/Enums/HTTPMethod.php | 2 ++ src/Traits/Request/Patch.php | 14 ++++++++++++++ tests/Traits/Request/PatchTest.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 src/Traits/Request/Patch.php create mode 100644 tests/Traits/Request/PatchTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d09d0..487c18a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.2.0] - 2018-09-19 +### Summary +- Added support for `PATCH` HTTP method + +### Added +- `Traits\Request\Patch` + ## [3.1.0] - 2018-07-01 ### Summary - Overhauled authentication (#43) diff --git a/src/Enums/HTTPMethod.php b/src/Enums/HTTPMethod.php index 66464ed..3f13b77 100644 --- a/src/Enums/HTTPMethod.php +++ b/src/Enums/HTTPMethod.php @@ -10,6 +10,7 @@ * @method static HTTPMethod DELETE() * @method static HTTPMethod GET() * @method static HTTPMethod OPTIONS() + * @method static HTTPMethod PATCH() * @method static HTTPMethod POST() * @method static HTTPMethod PUT() */ @@ -19,6 +20,7 @@ class HTTPMethod extends Enum // Other methods exist, but these are the only relevant ones for RESTful // APIs const GET = 'GET'; + const PATCH = 'PATCH'; const POST = 'POST'; const PUT = 'PUT'; const DELETE = 'DELETE'; diff --git a/src/Traits/Request/Patch.php b/src/Traits/Request/Patch.php new file mode 100644 index 0000000..c0db3fc --- /dev/null +++ b/src/Traits/Request/Patch.php @@ -0,0 +1,14 @@ + + * @covers :: + */ +class PatchTest extends \PHPUnit\Framework\TestCase +{ + + /** + * @covers ::getMethod + */ + public function testGetMethod() + { + $obj = new class { + use Patch; + }; + $this->assertEquals( + \Firehed\API\Enums\HTTPMethod::PATCH(), + $obj->getMethod(), + 'getMethod did not return HTTP PATCH' + ); + } +} From a502c134a20abd664c3511fcaa0716cfcc5f68ba Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 19 Sep 2018 14:56:17 -0700 Subject: [PATCH 2/9] Define renderResponse conditionally to work around some kind of weird interaction/regression introduced in phpunit 7.3 --- src/renderResponse.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderResponse.php b/src/renderResponse.php index c051e92..2a19272 100644 --- a/src/renderResponse.php +++ b/src/renderResponse.php @@ -12,7 +12,9 @@ * * @deprecated 3.1.0 Use ResponseRenderer instead */ -function renderResponse(ResponseInterface $response) -{ - ResponseRenderer::render($response); +if (!function_exists(__NAMESPACE__.'\renderResponse')) { + function renderResponse(ResponseInterface $response) + { + ResponseRenderer::render($response); + } } From 2f0a045712c0f5de187091e9023d05970c802ca2 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 24 Oct 2018 16:32:43 -0700 Subject: [PATCH 3/9] Allow Diactoros 1.3 or 2.0 (#88) --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/Dispatcher.php | 2 ++ tests/DispatcherTest.php | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 487c18a..1212abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.2.1] - 2018-10-24 +### Summary +- Widen range of supported Zend Diactoros version + ## [3.2.0] - 2018-09-19 ### Summary - Added support for `PATCH` HTTP method diff --git a/composer.json b/composer.json index 369b281..c268f48 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^1.0", - "zendframework/zend-diactoros": "^1.3" + "zendframework/zend-diactoros": "^1.3 || ^2.0" }, "suggest": { "firehed/inputobjects": "Pre-made Input components for validation" diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 1ca3dee..365a60e 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -161,6 +161,8 @@ private function transformRequestToServerRequest(RequestInterface $request): Ser foreach ($request->getHeaders() as $name => $values) { $serverRequest = $serverRequest->withHeader($name, $values); } + // ZD2 hints the return type of withHeader to MessageInterface not SRI + assert($serverRequest instanceof ServerRequestInterface); return $serverRequest; } diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index a25507f..15014e7 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -92,6 +92,7 @@ public function testSetRequestReturnsSelf() { $d = new Dispatcher(); $req = $this->createMock(RequestInterface::class); + $req->method('getMethod')->willReturn('GET'); $req->method('getHeaders')->willReturn([]); $req->method('getBody')->willReturn($this->createMock(StreamInterface::class)); $req->method('getUri')->willReturn($this->createMock(UriInterface::class)); From c4a3fa7b5356dad5b2b98c6ac51be774d106d2dd Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Tue, 12 Feb 2019 14:14:59 -0800 Subject: [PATCH 4/9] Fixes for PHPUnit 8 (#94) --- CHANGELOG.md | 3 ++ phpstan.neon | 4 ++ src/Traits/EndpointTestCases.php | 4 +- src/Traits/Testing/PHPUnit8Shim.php | 24 +++++++++++ src/Traits/Testing/PHPUnit8ShimPHPGTE71.php | 42 +++++++++++++++++++ src/Traits/Testing/PHPUnit8ShimPHPLT71.php | 31 ++++++++++++++ tests/DispatcherTest.php | 10 +++-- .../Traits/Authentication/BearerTokenTest.php | 6 +-- tests/Traits/Authentication/NoneTest.php | 6 +-- tests/Traits/EndpointTestCasesTest.php | 6 +-- 10 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 src/Traits/Testing/PHPUnit8Shim.php create mode 100644 src/Traits/Testing/PHPUnit8ShimPHPGTE71.php create mode 100644 src/Traits/Testing/PHPUnit8ShimPHPLT71.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1212abe..1523dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.2.2] - 2019-02-12 +### Summary +- Change tests to resolve deprecation warnings that appear under PHPUnit 8 (#93) ## [3.2.1] - 2018-10-24 ### Summary diff --git a/phpstan.neon b/phpstan.neon index 35d413e..acce15b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon +parameters: + ignoreErrors: + - '#Call to an undefined static method PHPUnit\\Framework\\TestCase::assertIs(Array|Bool|String)\(\)#' + reportUnmatchedIgnoredErrors: false diff --git a/src/Traits/EndpointTestCases.php b/src/Traits/EndpointTestCases.php index 0956677..50d9e9d 100644 --- a/src/Traits/EndpointTestCases.php +++ b/src/Traits/EndpointTestCases.php @@ -17,6 +17,7 @@ trait EndpointTestCases { use HandlesOwnErrorsTestCases; + use Testing\PHPUnit8Shim; use ValidationTestTrait; /** @@ -47,8 +48,7 @@ protected function getValidation(): ValidationInterface public function testGetUri(string $uri, bool $match, array $expectedMatches) { $endpoint = $this->getEndpoint(); - $this->assertInternalType( - 'string', + $this->assertIsString( $endpoint->getUri(), 'getUri did not return a string' ); diff --git a/src/Traits/Testing/PHPUnit8Shim.php b/src/Traits/Testing/PHPUnit8Shim.php new file mode 100644 index 0000000..262b2c8 --- /dev/null +++ b/src/Traits/Testing/PHPUnit8Shim.php @@ -0,0 +1,24 @@ +=')) { + trait PHPUnit8Shim + { + use PHPUnit8ShimPHPGTE71; + } +} else { + trait PHPUnit8Shim + { + use PHPUnit8ShimPHPLT71; + } +} diff --git a/src/Traits/Testing/PHPUnit8ShimPHPGTE71.php b/src/Traits/Testing/PHPUnit8ShimPHPGTE71.php new file mode 100644 index 0000000..79b13a4 --- /dev/null +++ b/src/Traits/Testing/PHPUnit8ShimPHPGTE71.php @@ -0,0 +1,42 @@ +expectException(BadMethodCallException::class); + $this->expectExceptionCode(500); $ret = $d->dispatch(); } /** * @covers ::dispatch - * @expectedException OutOfBoundsException - * @expectedExceptionCode 404 */ public function testNoRouteMatchReturns404() { $req = $this->getMockRequestWithUriPath('/'); + $this->expectException(OutOfBoundsException::class); + $this->expectExceptionCode(404); $ret = (new Dispatcher()) ->setRequest($req) ->setEndpointList([]) // No routes diff --git a/tests/Traits/Authentication/BearerTokenTest.php b/tests/Traits/Authentication/BearerTokenTest.php index 7f5a432..dd249b9 100644 --- a/tests/Traits/Authentication/BearerTokenTest.php +++ b/tests/Traits/Authentication/BearerTokenTest.php @@ -116,13 +116,13 @@ private function getEndpoint($setCallback = true): EndpointInterface use Traits\Request\Get; use Traits\Input\NoRequired; use Traits\Input\NoOptional; - function getUri(): string + public function getUri(): string { } - function handleException(\Throwable $e): Message\ResponseInterface + public function handleException(\Throwable $e): Message\ResponseInterface { } - function execute(SafeInput $input): Message\ResponseInterface + public function execute(SafeInput $input): Message\ResponseInterface { } }; diff --git a/tests/Traits/Authentication/NoneTest.php b/tests/Traits/Authentication/NoneTest.php index 6263e50..417341b 100644 --- a/tests/Traits/Authentication/NoneTest.php +++ b/tests/Traits/Authentication/NoneTest.php @@ -25,13 +25,13 @@ public function testAuthenticate() use Traits\Request\Get; use Traits\Input\NoRequired; use Traits\Input\NoOptional; - function getUri(): string + public function getUri(): string { } - function handleException(\Throwable $e): Message\ResponseInterface + public function handleException(\Throwable $e): Message\ResponseInterface { } - function execute(SafeInput $input): Message\ResponseInterface + public function execute(SafeInput $input): Message\ResponseInterface { } }; diff --git a/tests/Traits/EndpointTestCasesTest.php b/tests/Traits/EndpointTestCasesTest.php index 12a9bf1..c67bb1e 100644 --- a/tests/Traits/EndpointTestCasesTest.php +++ b/tests/Traits/EndpointTestCasesTest.php @@ -50,9 +50,9 @@ public function testUris() $data = $this->uris(); foreach ($data as $testCase) { list($uri, $shouldMatch, $matches) = $testCase; - $this->assertInternalType('string', $uri); - $this->assertInternalType('bool', $shouldMatch); - $this->assertInternalType('array', $matches); + $this->assertIsString($uri); + $this->assertIsBool($shouldMatch); + $this->assertIsArray($matches); } } From 4b1e1fa75f26f0ff573b8ad328e8d2aac545e209 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Sat, 11 Feb 2023 14:29:33 -0800 Subject: [PATCH 5/9] Expand a bunch of version constraints --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index c268f48..267b50b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "firehed/api", "require": { - "php": "^7.0", + "php": "^7.0 || ^8.0", "firehed/common": "^1.0", "firehed/input": "^2.0", "psr/container": "^1.0", @@ -24,9 +24,9 @@ }, "require-dev": { "firehed/arctools": "^1.0", - "phpstan/phpstan": "^0.9.2", - "phpstan/phpstan-phpunit": "^0.9.4", - "phpunit/phpunit": "^6.0 | ^7.0", + "phpstan/phpstan": "^0.9.2 || ^1.0", + "phpstan/phpstan-phpunit": "^0.9.4 || ^1.0", + "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", "squizlabs/php_codesniffer": "^3.1" }, "autoload": { From 56f8df0a7d66152c09e9bdbe2a0dc29f702bd7d8 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Sat, 11 Feb 2023 14:30:18 -0800 Subject: [PATCH 6/9] Test fixes --- tests/ContainerTest.php | 2 +- tests/DispatcherTest.php | 4 ++-- tests/Traits/Authentication/BearerTokenTest.php | 4 ++-- tests/Traits/HandlesOwnErrorsTestCasesTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index f6fc4c8..958f0e8 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -15,7 +15,7 @@ class ContainerTest extends \PHPUnit\Framework\TestCase /** @var Container */ private $c; - public function setUp() + public function setUp(): void { $this->c = new Container(['key' => 'value']); } diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 675d811..c65ad4c 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -34,13 +34,13 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase private $reporting; - public function setUp() + public function setUp(): void { $this->reporting = error_reporting(); error_reporting($this->reporting & ~E_USER_DEPRECATED); } - public function tearDown() + public function tearDown(): void { error_reporting($this->reporting); } diff --git a/tests/Traits/Authentication/BearerTokenTest.php b/tests/Traits/Authentication/BearerTokenTest.php index dd249b9..53559ee 100644 --- a/tests/Traits/Authentication/BearerTokenTest.php +++ b/tests/Traits/Authentication/BearerTokenTest.php @@ -23,13 +23,13 @@ class BearerTokenTest extends \PHPUnit\Framework\TestCase private $reporting; - public function setUp() + public function setUp(): void { $this->reporting = error_reporting(); error_reporting($this->reporting & ~E_USER_DEPRECATED); } - public function tearDown() + public function tearDown(): void { error_reporting($this->reporting); } diff --git a/tests/Traits/HandlesOwnErrorsTestCasesTest.php b/tests/Traits/HandlesOwnErrorsTestCasesTest.php index 774df37..df43254 100644 --- a/tests/Traits/HandlesOwnErrorsTestCasesTest.php +++ b/tests/Traits/HandlesOwnErrorsTestCasesTest.php @@ -15,7 +15,7 @@ class HandlesOwnErrorsTestCasesTest extends \PHPUnit\Framework\TestCase { use HandlesOwnErrorsTestCases; - public function setUp() + public function setUp(): void { $this->setAllowHandleExceptionToRethrow(true); } From 19864d2e062e9064680e5ab0ca6dad85ab78ef0f Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Sat, 11 Feb 2023 14:37:59 -0800 Subject: [PATCH 7/9] Hack PHPUnit shim for >=10 compat --- src/Traits/Testing/PHPUnit8Shim.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Traits/Testing/PHPUnit8Shim.php b/src/Traits/Testing/PHPUnit8Shim.php index 262b2c8..05f899d 100644 --- a/src/Traits/Testing/PHPUnit8Shim.php +++ b/src/Traits/Testing/PHPUnit8Shim.php @@ -3,6 +3,8 @@ namespace Firehed\API\Traits\Testing; +use PHPUnit\Runner\Version; + /** * phpcs:disable * @@ -11,7 +13,12 @@ * * @internal */ -if (version_compare(PHP_VERSION, '7.1.0', '>=')) { +if (class_exists(Version::class) && version_compare(Version::id(), '10.0.0', '>=')) { + trait PHPUnit8Shim + { + // Intentionally empty + } +} elseif (version_compare(PHP_VERSION, '7.1.0', '>=')) { trait PHPUnit8Shim { use PHPUnit8ShimPHPGTE71; From 5e31e8b97f41da9251dcecb620b2d530dfd7375f Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Sat, 11 Feb 2023 14:42:40 -0800 Subject: [PATCH 8/9] Fix some static class issues --- src/Traits/HandlesOwnErrorsTestCases.php | 2 +- tests/ConfigTest.php | 4 ++-- tests/Traits/Authentication/BearerTokenTest.php | 2 +- tests/Traits/ResponseBuilderTest.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Traits/HandlesOwnErrorsTestCases.php b/src/Traits/HandlesOwnErrorsTestCases.php index 1d2dba7..73fbd6f 100644 --- a/src/Traits/HandlesOwnErrorsTestCases.php +++ b/src/Traits/HandlesOwnErrorsTestCases.php @@ -59,7 +59,7 @@ public function testHandleException(Throwable $e) * * @return array> */ - public function exceptionsToHandle(): array + public static function exceptionsToHandle(): array { return [ [new \Exception()], diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 13f69e7..0320f09 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -78,7 +78,7 @@ public function testLoad(string $file, string $exceptionClass = null) $this->assertInstanceOf(ContainerInterface::class, $config); } - public function constructProvider(): array + public static function constructProvider(): array { return [ [ @@ -120,7 +120,7 @@ public function constructProvider(): array ]; } - public function loadProvider(): array + public static function loadProvider(): array { return [ [__DIR__.'/fixtures/valid_apiconfig.json'], diff --git a/tests/Traits/Authentication/BearerTokenTest.php b/tests/Traits/Authentication/BearerTokenTest.php index 53559ee..3404085 100644 --- a/tests/Traits/Authentication/BearerTokenTest.php +++ b/tests/Traits/Authentication/BearerTokenTest.php @@ -143,7 +143,7 @@ private function getRequest(string $headerValue = null): Message\RequestInterfac } // Data provider for testAuthenticate - public function bearerTokens(): array + public static function bearerTokens(): array { return [ ['sometoken'], diff --git a/tests/Traits/ResponseBuilderTest.php b/tests/Traits/ResponseBuilderTest.php index 5eba311..8eb2bfa 100644 --- a/tests/Traits/ResponseBuilderTest.php +++ b/tests/Traits/ResponseBuilderTest.php @@ -135,7 +135,7 @@ public function testtextResponse() } - public function jsonData(): array + public static function jsonData(): array { return [ [1], From d41c82f6c2f2ae29cc1fc6a311b199347b891496 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Sat, 11 Feb 2023 14:44:24 -0800 Subject: [PATCH 9/9] Expand container --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 267b50b..3fbe12f 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "php": "^7.0 || ^8.0", "firehed/common": "^1.0", "firehed/input": "^2.0", - "psr/container": "^1.0", + "psr/container": "^1.0 || ^2.0", "psr/http-message": "^1.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0",