From 42761aecd9f82582c910145d9f37d3d00ccba02e Mon Sep 17 00:00:00 2001 From: osteel Date: Thu, 15 Jun 2023 18:02:01 +0100 Subject: [PATCH] updated dependencies --- .github/workflows/ci.yml | 4 ++-- composer.json | 2 +- rector.php | 1 + tests/Adapters/HttpFoundationAdapterTest.php | 5 +---- tests/TestCase.php | 16 ++++------------ tests/ValidatorBuilderTest.php | 2 +- tests/ValidatorTest.php | 11 ++++++----- 7 files changed, 16 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcacff8..4cb5b25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,10 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - tools: cs2pr, phpcs + tools: phpcs - name: Run phpcs - run: phpcs -q --report=checkstyle | cs2pr + run: phpcs tests: name: Tests diff --git a/composer.json b/composer.json index 3200039..4f6b9e3 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": "^8.0", "ext-json": "*", - "league/openapi-psr7-validator": "^0.19", + "league/openapi-psr7-validator": "^0.21", "nyholm/psr7": "^1.0", "psr/http-message": "^1.0", "symfony/http-foundation": "^4.0 || ^5.0 || ^6.0", diff --git a/rector.php b/rector.php index eca49a8..52a4828 100644 --- a/rector.php +++ b/rector.php @@ -8,6 +8,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src', + __DIR__ . '/tests', ]); $rectorConfig->sets([LevelSetList::UP_TO_PHP_80]); diff --git a/tests/Adapters/HttpFoundationAdapterTest.php b/tests/Adapters/HttpFoundationAdapterTest.php index ff7e46e..1d46dd8 100644 --- a/tests/Adapters/HttpFoundationAdapterTest.php +++ b/tests/Adapters/HttpFoundationAdapterTest.php @@ -12,10 +12,7 @@ class HttpFoundationAdapterTest extends TestCase { - /** - * @var HttpFoundationAdapter - */ - private $sut; + private HttpFoundationAdapter $sut; protected function setUp(): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index 69929ab..de0a3da 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,13 +28,12 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase /** * Return a HttpFoundation response with the provided content. * - * @param array $content * @return Response */ protected function httpFoundationResponse(array $content = null): Response { return new Response( - $content ? json_encode($content) : '', + $content ? json_encode($content, JSON_THROW_ON_ERROR) : '', $content ? Response::HTTP_OK : Response::HTTP_NO_CONTENT, $content ? ['Content-Type' => 'application/json'] : [] ); @@ -43,7 +42,6 @@ protected function httpFoundationResponse(array $content = null): Response /** * Return a PSR-7 response with the provided content. * - * @param array $content * @return ResponseInterface */ protected function psr7Response(array $content = null): ResponseInterface @@ -55,7 +53,7 @@ protected function psr7Response(array $content = null): ResponseInterface return $response; } - $response->method('getBody')->willReturn(json_encode($content)); + $response->method('getBody')->willReturn(json_encode($content, JSON_THROW_ON_ERROR)); $response->method('getStatusCode')->willReturn(Response::HTTP_OK); $response->method('getHeader')->willReturn(['application/json']); @@ -65,9 +63,6 @@ protected function psr7Response(array $content = null): ResponseInterface /** * Return a HttpFoundation request with the provided content. * - * @param string $uri - * @param string $method - * @param array $content * @return Request */ protected function httpFoundationRequest(string $uri, string $method, array $content = null): Request @@ -79,16 +74,13 @@ protected function httpFoundationRequest(string $uri, string $method, array $con [], [], $content ? ['CONTENT_TYPE' => 'application/json'] : [], - $content ? json_encode($content) : '' + $content ? json_encode($content, JSON_THROW_ON_ERROR) : '' ); } /** * Return a PSR-7 request with the provided content. * - * @param string $uri - * @param string $method - * @param array $content * @return ServerRequestInterface */ protected function psr7Request( @@ -98,7 +90,7 @@ protected function psr7Request( ): ServerRequestInterface { $psr17Factory = new Psr17Factory(); $uri = $psr17Factory->createUri(self::BASE_URI . $uri); - $stream = $psr17Factory->createStream(json_encode($content)); + $stream = $psr17Factory->createStream(json_encode($content, JSON_THROW_ON_ERROR)); $request = $psr17Factory->createServerRequest($method, $uri); if ($content) { diff --git a/tests/ValidatorBuilderTest.php b/tests/ValidatorBuilderTest.php index 92ddb49..45cc36d 100644 --- a/tests/ValidatorBuilderTest.php +++ b/tests/ValidatorBuilderTest.php @@ -58,7 +58,7 @@ public function testItDoesNotSetTheAdapterBecauseItsTypeIsInvalid() public function testItSetsTheAdapter() { ValidatorBuilder::fromYaml(self::$yamlDefinition) - ->setAdapter(get_class($this->createMock(AdapterInterface::class))); + ->setAdapter($this->createMock(AdapterInterface::class)::class); // No exception means the test was successful. $this->assertTrue(true); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index ce49d2a..9eaa7f7 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -6,14 +6,12 @@ use Osteel\OpenApi\Testing\Exceptions\ValidationException; use Osteel\OpenApi\Testing\Tests\TestCase; +use Osteel\OpenApi\Testing\Validator; use Osteel\OpenApi\Testing\ValidatorBuilder; class ValidatorTest extends TestCase { - /** - * @var Validator - */ - private $sut; + private Validator $sut; protected function setUp(): void { @@ -42,10 +40,11 @@ public function requestTypeProvider(): array public function testItDoesNotValidateTheRequestWithoutPayload(string $method) { $this->expectException(ValidationException::class); + $this->expectExceptionMessage('OpenAPI spec contains no such operation [/test,foo]'); $request = $this->$method(static::PATH, 'delete'); - $this->sut->validate($request, static::PATH, $method); + $this->sut->validate($request, static::PATH, 'foo'); } /** @@ -65,6 +64,7 @@ public function testItValidatesTheRequestWithoutPayload(string $method) public function testItDoesNotValidateTheRequestWithPayload(string $method) { $this->expectException(ValidationException::class); + $this->expectExceptionMessage('Body does not match schema for content-type "application/json" for Request [post /test]: Keyword validation failed: Required property \'foo\' must be present in the object Field: foo'); $request = $this->$method(static::PATH, 'post', ['baz' => 'bar']); @@ -144,6 +144,7 @@ public function responseTypeProvider(): array public function testItDoesNotValidateTheResponse(string $method) { $this->expectException(ValidationException::class); + $this->expectExceptionMessage('Body does not match schema for content-type "application/json" for Response [get /test 200]: Keyword validation failed: Required property \'foo\' must be present in the object Field: foo'); $response = $this->$method(['baz' => 'bar']);