Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A required request body will not fail tests, if no body is given #3

Closed
Zeromax opened this issue Sep 19, 2017 · 6 comments
Closed

A required request body will not fail tests, if no body is given #3

Zeromax opened this issue Sep 19, 2017 · 6 comments
Assignees
Labels

Comments

@Zeromax
Copy link

Zeromax commented Sep 19, 2017

Hello there, thanks for this great package.

I have the following problem: If I have a required request body (defined in swagger), but non is given in my test, then the test does not fail.
I expected that the test will fail.

This seems to be a bug:
https://github.com/byjg/php-swagger-test/blob/master/src/SwaggerTestCase.php#L80-L82

I think in SwaggerRequestBody the exception should only be thrown if $body is not empty and no parameter body is found.

@byjg
Copy link
Owner

byjg commented Sep 19, 2017

Hi,

FIrst of all, thank you :)

I believe you are right. I'll found some time to touch in the code this week and fix it. Meanwhile, If you have some idea or piece of code it will welcome.

@byjg byjg self-assigned this Sep 19, 2017
@byjg byjg added the bug label Sep 19, 2017
@Zeromax
Copy link
Author

Zeromax commented Sep 19, 2017

Thanks for the fast reply.

My workaround at the moment:

$bodyRequestDef = $this->swaggerSchema->getRequestParameters($expectedResponse->path, $expectedResponse->method);
try {
    $bodyRequestDef->match($requestBody);
} catch (InvalidDefinitionException $e) {
    if ('There is no body for match' !== $e->getMessage()) {
        // throw exception if not the body exception
        throw $e;
    }
    if ('There is no body for match' === $e->getMessage() && !empty($content)) {
        // throw exception if there is no body in swagger, but a body given
        throw $e;
    }
}

But I really think there is a better solution ;)

@byjg
Copy link
Owner

byjg commented Sep 19, 2017 via email

@byjg
Copy link
Owner

byjg commented Sep 20, 2017

I did a fix. I'd like you test if before I merge it .

In your composer.json do it:

{
    "require": {
        "byjg/swagger-test": "1.1.0.x-dev"
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

@Zeromax
Copy link
Author

Zeromax commented Sep 20, 2017

That's perfect. Thanks for this fast fix!

@byjg byjg mentioned this issue Sep 20, 2017
Merged
@byjg
Copy link
Owner

byjg commented Sep 20, 2017

I published a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants