diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d09d0..1523dd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ 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 +- Widen range of supported Zend Diactoros version + +## [3.2.0] - 2018-09-19 +### Summary +- Added support for `PATCH` HTTP method + +### Added +- `Traits\Request\Patch` ## [3.1.0] - 2018-07-01 ### Summary diff --git a/composer.json b/composer.json index 369b281..3fbe12f 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,15 @@ { "name": "firehed/api", "require": { - "php": "^7.0", + "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", "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" @@ -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": { 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/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/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/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/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/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 @@ +=')) { + trait PHPUnit8Shim + { + // Intentionally empty + } +} elseif (version_compare(PHP_VERSION, '7.1.0', '>=')) { + 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 @@ +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/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 a25507f..c65ad4c 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -4,11 +4,13 @@ namespace Firehed\API; +use BadMethodCallException; use Exception; use Firehed\API\Authentication; use Firehed\API\Authorization; use Firehed\API\Interfaces\EndpointInterface; use Firehed\API\Errors\HandlerInterface; +use OutOfBoundsException; use Psr\Container\ContainerInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -32,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); } @@ -92,6 +94,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)); @@ -424,24 +427,24 @@ public function testErrorInResponseHandler() /** * @covers ::dispatch - * @expectedException BadMethodCallException - * @expectedExceptionCode 500 */ public function testDispatchThrowsWhenMissingData() { $d = new Dispatcher(); + $this->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..3404085 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); } @@ -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 { } }; @@ -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/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); } } 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); } diff --git a/tests/Traits/Request/PatchTest.php b/tests/Traits/Request/PatchTest.php new file mode 100644 index 0000000..efc3b73 --- /dev/null +++ b/tests/Traits/Request/PatchTest.php @@ -0,0 +1,28 @@ + + * @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' + ); + } +} 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],