diff --git a/tests/AbstractRequesterTest.php b/tests/AbstractRequesterTest.php index d4ed7e9..b259efa 100644 --- a/tests/AbstractRequesterTest.php +++ b/tests/AbstractRequesterTest.php @@ -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, @@ -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"}')); @@ -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); @@ -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, @@ -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, @@ -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, diff --git a/tests/OpenApiRequestBodyTest.php b/tests/OpenApiRequestBodyTest.php index 52bec97..af95a49 100644 --- a/tests/OpenApiRequestBodyTest.php +++ b/tests/OpenApiRequestBodyTest.php @@ -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 @@ -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 @@ -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, @@ -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 @@ -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); } @@ -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 @@ -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 @@ -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", @@ -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 @@ -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", @@ -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 @@ -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", diff --git a/tests/OpenApiResponseBodyTest.php b/tests/OpenApiResponseBodyTest.php index 3af37ad..1d6536a 100644 --- a/tests/OpenApiResponseBodyTest.php +++ b/tests/OpenApiResponseBodyTest.php @@ -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 @@ -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, @@ -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 @@ -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, @@ -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 @@ -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, @@ -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 @@ -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', @@ -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 @@ -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); @@ -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 @@ -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 = [ [ @@ -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); } diff --git a/tests/OpenApiSchemaTest.php b/tests/OpenApiSchemaTest.php index 26ca8ca..d084485 100644 --- a/tests/OpenApiSchemaTest.php +++ b/tests/OpenApiSchemaTest.php @@ -332,7 +332,6 @@ public function testGetPathPatternMatch2() } /** - * @expectedException \ByJG\ApiTools\Exception\PathNotFoundException * * @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException * @throws \ByJG\ApiTools\Exception\NotMatchedException @@ -340,11 +339,12 @@ public function testGetPathPatternMatch2() */ public function testGetPathFail() { + $this->setExpectedException(\ByJG\ApiTools\Exception\PathNotFoundException::class); + $this->openapiObject->getPathDefinition('/v2/pets', 'get'); } /** - * @expectedException \ByJG\ApiTools\Exception\HttpMethodNotFoundException * * @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException * @throws \ByJG\ApiTools\Exception\NotMatchedException @@ -352,6 +352,8 @@ public function testGetPathFail() */ public function testPathExistsButMethodDont() { + $this->setExpectedException(\ByJG\ApiTools\Exception\HttpMethodNotFoundException::class); + $this->openapiObject->getPathDefinition('/v2/pet', 'GET'); } @@ -399,35 +401,38 @@ public function testGetPathStructure() } /** - * @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed() { + $this->setExpectedException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class); + $this->openapiObject->getDefinition('Order'); } /** - * @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed2() { + $this->setExpectedException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class); + $this->openapiObject->getDefinition('1/2/Order'); } /** - * @expectedException \ByJG\ApiTools\Exception\DefinitionNotFoundException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed3() { + $this->setExpectedException(\ByJG\ApiTools\Exception\DefinitionNotFoundException::class); + $this->openapiObject->getDefinition('#/components/schemas/OrderNOtFound'); } diff --git a/tests/SwaggerRequestBodyTest.php b/tests/SwaggerRequestBodyTest.php index 33bbae2..2e6301b 100644 --- a/tests/SwaggerRequestBodyTest.php +++ b/tests/SwaggerRequestBodyTest.php @@ -29,8 +29,6 @@ public function testMatchRequestBody() } /** - * @expectedException \ByJG\ApiTools\Exception\RequiredArgumentNotFound - * @expectedExceptionMessage The body is required * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\GenericSwaggerException @@ -43,13 +41,14 @@ public function testMatchRequestBody() */ public function testMatchRequiredRequestBodyEmpty() { + $this->expectException(\ByJG\ApiTools\Exception\RequiredArgumentNotFound::class); + $this->expectExceptionMessage('The body is required'); + $requestParameter = self::swaggerSchema()->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 @@ -62,6 +61,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'); + $requestParameter = self::swaggerSchema()->getRequestParameters('/v2/pet/1', 'get'); $body = [ "id" => "10", @@ -75,8 +77,6 @@ public function testMatchInexistantBodyDefinition() } /** - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Path expected an integer value * * @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException * @throws \ByJG\ApiTools\Exception\NotMatchedException @@ -84,13 +84,14 @@ public function testMatchInexistantBodyDefinition() */ public function testMatchDataType() { + $this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class); + $this->expectExceptionMessage('Path expected an integer value'); + self::swaggerSchema()->getRequestParameters('/v2/pet/STRING', 'get'); $this->assertTrue(true); } /** - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Required property * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\GenericSwaggerException @@ -103,6 +104,9 @@ public function testMatchDataType() */ public function testMatchRequestBodyRequired1() { + $this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class); + $this->expectExceptionMessage('Required property'); + $body = [ "id" => "10", "status" => "pending", @@ -115,8 +119,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 @@ -129,6 +131,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", @@ -212,8 +217,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 @@ -226,6 +229,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", diff --git a/tests/SwaggerResponseBodyTest.php b/tests/SwaggerResponseBodyTest.php index 99b9acd..567f53e 100644 --- a/tests/SwaggerResponseBodyTest.php +++ b/tests/SwaggerResponseBodyTest.php @@ -53,8 +53,6 @@ public function testMatchResponseBody() } /** - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Value 'notfound' in 'status' not matched in ENUM * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\GenericSwaggerException @@ -66,6 +64,9 @@ public function testMatchResponseBody() */ 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, @@ -79,8 +80,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 @@ -92,6 +91,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, @@ -105,8 +107,6 @@ public function testMatchResponseBodyWrongNumber() } /** - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage The property(ies) 'more' has not defined in '#/definitions/Order' * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\GenericSwaggerException @@ -118,6 +118,9 @@ public function testMatchResponseBodyWrongNumber() */ public function testMatchResponseBodyMoreThanExpected() { + $this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class); + $this->expectExceptionMessage('The property(ies) \'more\' has not defined in \'#/definitions/Order\''); + $body = [ "id" => "50", "petId" => 50, @@ -177,8 +180,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 @@ -190,6 +191,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', @@ -216,8 +220,6 @@ public function testMatchResponseBodyEmpty() } /** - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Expected empty body for * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\GenericSwaggerException @@ -229,6 +231,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::swaggerSchema()->getResponseParameters('/v2/pet/10', 'get', 400); $this->assertTrue($responseParameter->match($body)); @@ -451,8 +456,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 @@ -464,6 +467,9 @@ public function testIssue9() */ public function testIssue9Error() { + $this->expectExceptionRegExp(\ByJG\ApiTools\Exception\InvalidRequestException::class); + $this->expectExceptionMessage('"I expected an array here.*"'); + $body = [ [ @@ -515,11 +521,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->swaggerSchema()->getResponseParameters('/v2/user/login', 'get', 503); } diff --git a/tests/SwaggerSchemaTest.php b/tests/SwaggerSchemaTest.php index 66362c4..db943c3 100644 --- a/tests/SwaggerSchemaTest.php +++ b/tests/SwaggerSchemaTest.php @@ -352,7 +352,6 @@ public function testGetPathPatternMatch2() } /** - * @expectedException \ByJG\ApiTools\Exception\PathNotFoundException * * @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException * @throws \ByJG\ApiTools\Exception\NotMatchedException @@ -360,11 +359,12 @@ public function testGetPathPatternMatch2() */ public function testGetPathFail() { + $this->setExpectedException(\ByJG\ApiTools\Exception\PathNotFoundException::class); + $this->object->getPathDefinition('/v2/pets', 'get'); } /** - * @expectedException \ByJG\ApiTools\Exception\HttpMethodNotFoundException * * @throws \ByJG\ApiTools\Exception\HttpMethodNotFoundException * @throws \ByJG\ApiTools\Exception\NotMatchedException @@ -372,6 +372,8 @@ public function testGetPathFail() */ public function testPathExistsButMethodDont() { + $this->setExpectedException(\ByJG\ApiTools\Exception\HttpMethodNotFoundException::class); + $this->object->getPathDefinition('/v2/pet', 'GET'); } @@ -436,35 +438,38 @@ public function testGetPathStructure() } /** - * @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed() { + $this->setExpectedException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class); + $this->object->getDefinition('Order'); } /** - * @expectedException \ByJG\ApiTools\Exception\InvalidDefinitionException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed2() { + $this->setExpectedException(\ByJG\ApiTools\Exception\InvalidDefinitionException::class); + $this->object->getDefinition('1/2/Order'); } /** - * @expectedException \ByJG\ApiTools\Exception\DefinitionNotFoundException * * @throws \ByJG\ApiTools\Exception\DefinitionNotFoundException * @throws \ByJG\ApiTools\Exception\InvalidDefinitionException */ public function testGetDefinitionFailed3() { + $this->setExpectedException(\ByJG\ApiTools\Exception\DefinitionNotFoundException::class); + $this->object->getDefinition('#/definitions/OrderNOtFound'); } diff --git a/tests/TestingTestCase.php b/tests/TestingTestCase.php index 2488fc1..427c3a3 100644 --- a/tests/TestingTestCase.php +++ b/tests/TestingTestCase.php @@ -75,11 +75,12 @@ public function testPost() * @throws \ByJG\ApiTools\Exception\PathNotFoundException * @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Required property 'name' */ public function testAddError() { + $this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class); + $this->expectExceptionMessage('Required property \'name\''); + $request = new ApiRequester(); $request ->withMethod('POST') @@ -103,11 +104,12 @@ public function testAddError() * @throws \ByJG\ApiTools\Exception\PathNotFoundException * @throws \ByJG\ApiTools\Exception\StatusCodeNotMatchedException - * @expectedException \ByJG\ApiTools\Exception\NotMatchedException - * @expectedExceptionMessage Expected empty body */ public function testPostError() { + $this->expectException(\ByJG\ApiTools\Exception\NotMatchedException::class); + $this->expectExceptionMessage('Expected empty body'); + $request = new ApiRequester(); $request ->withMethod('POST')