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

Update behavior of TestReponse::assertGraphQLErrorMessage to work whe… #1827

Merged
merged 1 commit into from Apr 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

- Update behavior of `TestReponse::assertGraphQLErrorMessage` to work when multiple errors are present

## 5.6.1

### Fixed
Expand Down
11 changes: 4 additions & 7 deletions src/Testing/TestResponseMixin.php
Expand Up @@ -67,13 +67,10 @@ public function assertGraphQLValidationPasses(): Closure
public function assertGraphQLErrorMessage(): Closure
{
return function (string $message) {
$this->assertJson([
'errors' => [
[
'message' => $message,
],
],
]);
Assert::assertContains(
$message,
$this->json('errors.*.message')
);

return $this;
};
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/ErrorTest.php
Expand Up @@ -120,4 +120,32 @@ public function testRethrowsInternalExceptions(): void
}
');
}

public function testReturnsMultipleErrors(): void
{
$this->schema = /** @lang GraphQL */'
input TestInput {
string: String!
integer: Int!
}

type Response {
status: String
}

type Query {
test(input: TestInput): [Response!]! @all(model: "Response")
}
';

$this->graphQL(/** @lang GraphQL */ '
{
test(input: {}) {
status
}
}
')
->assertGraphQLErrorMessage('Field TestInput.string of required type String! was not provided.')
->assertGraphQLErrorMessage('Field TestInput.integer of required type Int! was not provided.');
}
}