Skip to content

Commit

Permalink
Make compatible with latest PHPUnit version
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormattos authored and GoreSakuraba committed Jul 22, 2022
1 parent 1cd15f9 commit 20337a9
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 80 deletions.
30 changes: 18 additions & 12 deletions tests/AbstractRequesterTest.php
Expand Up @@ -47,11 +47,12 @@ public function testExpectOK()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Required property 'name'
*/
public function testExpectError()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Required property \'name\'');

$expectedResponse = Response::getInstance(200)
->withBody(new MemoryStream(json_encode([
"id" => 1,
Expand Down Expand Up @@ -126,11 +127,12 @@ public function testValidateAssertResponse404()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Expected empty body for GET 404 /v2/pet/1
*/
public function testValidateAssertResponse404WithContent()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Expected empty body for GET 404 /v2/pet/1');

$expectedResponse = Response::getInstance(404)
->withBody(new MemoryStream('{"error":"not found"}'));

Expand All @@ -152,11 +154,12 @@ public function testValidateAssertResponse404WithContent()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @expectedExceptionMessage Status code not matched: Expected 404, got 522
*/
public function testValidateAssertResponseNotExpected()
{
$this->expectException(\ByJG\ApiTools\Exception\StatusCodeNotMatchedException::class);
$this->expectExceptionMessage('Status code not matched: Expected 404, got 522');

$expectedResponse = Response::getInstance(522);

$request = new MockRequester($expectedResponse);
Expand Down Expand Up @@ -207,11 +210,12 @@ public function testValidateAssertHeaderContains()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Does not exists header 'X-Test' with value 'Different'
*/
public function testValidateAssertHeaderContainsWrongValue()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Does not exists header \'X-Test\' with value \'Different\'');

$expectedResponse = Response::getInstance(200)
->withBody(new MemoryStream(json_encode([
"id" => 1,
Expand Down Expand Up @@ -239,11 +243,12 @@ public function testValidateAssertHeaderContainsWrongValue()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Does not exists header 'X-Test' with value 'Different'
*/
public function testValidateAssertHeaderContainsNonExistent()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Does not exists header \'X-Test\' with value \'Different\'');

$expectedResponse = Response::getInstance(200)
->withBody(new MemoryStream(json_encode([
"id" => 1,
Expand Down Expand Up @@ -299,11 +304,12 @@ public function testValidateAssertBodyContains()
* @throws \ByJG\ApiTools\Exception\PathNotFoundException
* @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException
* @throws \ByJG\Util\Psr7\MessageException
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Body does not contain 'Doris'
*/
public function testValidateAssertBodyNotContains()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Body does not contain \'Doris\'');

$expectedResponse = Response::getInstance(200)
->withBody(new MemoryStream(json_encode([
"id" => 1,
Expand Down
35 changes: 21 additions & 14 deletions tests/OpenApiRequestBodyTest.php
Expand Up @@ -30,8 +30,6 @@ public function testMatchRequestBody()
}

/**
* @expectedException \ByJG\ApiTools\Exception\RequiredArgumentNotFound
* @expectedExceptionMessage The body is required
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -44,13 +42,14 @@ public function testMatchRequestBody()
*/
public function testMatchRequiredRequestBodyEmpty()
{
$this->expectException(\ByJG\ApiTools\Exception\RequiredArgumentNotFound::class);
$this->expectExceptionMessage('The body is required');

$requestParameter = self::openApiSchema()->getRequestParameters('/v2/store/order', 'post');
$this->assertTrue($requestParameter->match(null));
}

/**
* @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException
* @expectedExceptionMessage Body is passed but there is no request body definition
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -63,6 +62,9 @@ public function testMatchRequiredRequestBodyEmpty()
*/
public function testMatchInexistantBodyDefinition()
{
$this->expectException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class);
$this->expectExceptionMessage('Body is passed but there is no request body definition');

$body = [
"id" => "10",
"petId" => 50,
Expand All @@ -77,8 +79,6 @@ public function testMatchInexistantBodyDefinition()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Path expected an integer value
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException
Expand All @@ -88,6 +88,9 @@ public function testMatchInexistantBodyDefinition()
*/
public function testMatchDataType()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Path expected an integer value');

self::openApiSchema()->getRequestParameters('/v2/pet/STRING', 'get');
$this->assertTrue(true);
}
Expand All @@ -106,8 +109,6 @@ public function testMatchParameterInQuery2()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Path expected an integer value
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException
Expand All @@ -117,14 +118,15 @@ public function testMatchParameterInQuery2()
*/
public function testMatchParameterInQuery3()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Path expected an integer value');

self::openApiSchema3()->getRequestParameters('/tests/STRING?count=20&offset=2', 'get');
$this->assertTrue(true);
}


/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Required property
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -137,6 +139,9 @@ public function testMatchParameterInQuery3()
*/
public function testMatchRequestBodyRequired1()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Required property');

$body = [
"id" => "10",
"status" => "pending",
Expand All @@ -150,8 +155,6 @@ public function testMatchRequestBodyRequired1()
* It is not OK when allowNullValues is false (as by default) { name: null }
* https://stackoverflow.com/questions/45575493/what-does-required-in-openapi-really-mean
*
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Value of property 'name' is null, but should be of type 'string'
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -164,6 +167,9 @@ public function testMatchRequestBodyRequired1()
*/
public function testMatchRequestBodyRequiredNullsNotAllowed()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Value of property \'name\' is null, but should be of type \'string\'');

$body = [
"id" => "10",
"status" => "pending",
Expand Down Expand Up @@ -251,8 +257,6 @@ public function testMatchRequestBodyRequired_Issue21()

/**
* Issue #21
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Required property 'user_uuid'
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -265,6 +269,9 @@ public function testMatchRequestBodyRequired_Issue21()
*/
public function testMatchRequestBodyRequired_Issue21_Required()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Required property \'user_uuid\'');

// Missing Request
$body = [
"wallet_uuid" => "502a1aa3-5239-4d4b-af09-4dc24ac5f034",
Expand Down
35 changes: 21 additions & 14 deletions tests/OpenApiResponseBodyTest.php
Expand Up @@ -78,8 +78,6 @@ public function testMatchResponseBodyWithRefInsteadOfContent()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Value 'notfound' in 'status' not matched in ENUM
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -91,6 +89,9 @@ public function testMatchResponseBodyWithRefInsteadOfContent()
*/
public function testMatchResponseBodyEnumError()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Value \'notfound\' in \'status\' not matched in ENUM');

$body = [
"id" => 10,
"petId" => 50,
Expand All @@ -105,8 +106,6 @@ public function testMatchResponseBodyEnumError()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Expected 'id' to be numeric, but found 'ABC'
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -118,6 +117,9 @@ public function testMatchResponseBodyEnumError()
*/
public function testMatchResponseBodyWrongNumber()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Expected \'id\' to be numeric, but found \'ABC\'');

$body = [
"id" => "ABC",
"petId" => 50,
Expand All @@ -132,8 +134,6 @@ public function testMatchResponseBodyWrongNumber()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage The property(ies) 'more' has not defined in '#/components/schemas/Order'
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -145,6 +145,9 @@ public function testMatchResponseBodyWrongNumber()
*/
public function testMatchResponseBodyMoreThanExpected()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('The property(ies) \'more\' has not defined in \'#/components/schemas/Order\'');

$body = [
"id" => "50",
"petId" => 50,
Expand Down Expand Up @@ -207,8 +210,6 @@ public function testMatchResponseBodyAllowNullValues()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Value of property 'complete' is null, but should be of type 'boolean'
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -220,6 +221,9 @@ public function testMatchResponseBodyAllowNullValues()
*/
public function testMatchResponseBodyNotAllowNullValues()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Value of property \'complete\' is null, but should be of type \'boolean\'');

$body = [
"id" => 10,
"status" => 'placed',
Expand Down Expand Up @@ -248,8 +252,6 @@ public function testMatchResponseBodyEmpty()
}

/**
* @expectedException \ByJG\ApiTools\Exception\NotMatchedException
* @expectedExceptionMessage Expected empty body for
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -261,6 +263,9 @@ public function testMatchResponseBodyEmpty()
*/
public function testMatchResponseBodyNotEmpty()
{
$this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class);
$this->expectExceptionMessage('Expected empty body for');

$body = ['suppose'=>'not here'];

$responseParameter = self::openApiSchema()->getResponseParameters('/v2/pet/10', 'get', 400);
Expand Down Expand Up @@ -392,8 +397,6 @@ public function testIssue9()

/**
* Issue #9
* @expectedException \ByJG\ApiTools\Exception\InvalidRequestException
* @expectedExceptionMessageRegExp "I expected an array here.*"
*
* @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException
* @throws \ByJG\ApiTools\Exception\GenericSwaggerException
Expand All @@ -405,6 +408,9 @@ public function testIssue9()
*/
public function testIssue9Error()
{
$this->expectExceptionRegExp(\ByJG\ApiTools\Exception\InvalidRequestException::class);
$this->expectExceptionMessage('"I expected an array here.*"');

$body =
[
[
Expand Down Expand Up @@ -471,11 +477,12 @@ public function testResponseDefault()
}

/**
* @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException
* @expectedExceptionMessage Could not found status code '503'
*/
public function testResponseWithNoDefault()
{
$this->expectException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class);
$this->expectExceptionMessage('Could not found status code \'503\'');

$body = [];
$responseParameter = $this->openApiSchema()->getResponseParameters('/v2/user/login', 'get', 503);
}
Expand Down

0 comments on commit 20337a9

Please sign in to comment.