Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->sets([LevelSetList::UP_TO_PHP_80]);
Expand Down
5 changes: 1 addition & 4 deletions tests/Adapters/HttpFoundationAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

class HttpFoundationAdapterTest extends TestCase
{
/**
* @var HttpFoundationAdapter
*/
private $sut;
private HttpFoundationAdapter $sut;

protected function setUp(): void
{
Expand Down
16 changes: 4 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : []
);
Expand All @@ -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
Expand All @@ -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']);

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidatorBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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']);

Expand Down Expand Up @@ -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']);

Expand Down