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

PHPUnit testing Authentication - Logout #3

Closed
imd-solutions opened this issue Aug 9, 2019 · 1 comment
Closed

PHPUnit testing Authentication - Logout #3

imd-solutions opened this issue Aug 9, 2019 · 1 comment
Labels
question Further information is requested

Comments

@imd-solutions
Copy link

I have tried testing the authentication process with PHPUnit. I have managed to test all mutations apart from the logout.

$this->mutation('logout', ['status', 'message']); logout = the mutation, [status and message] = the LogoutResponse payload

When I run that, I get the below error message:

“message” => “Syntax Error: Expected Name, found Int”

It would seem that it is asking for a second parameter (Which I am guessing is the Authorization Bearer info), but in the schema, there are no parameters, just the payload:

Schema: logout: LogoutResponse!

I have got it working with another package:

$response = $this->postGraphQL([
'query' => 'mutation {
logout {
status
message
}
}'
], [
'Authorization' => 'Bearer '.$token
]);

But I would ideally like to get it working with your package.

Would appreciate a stir in the right direct.

@marvinrabe
Copy link
Owner

When using mutations with only two arguments the second argument is expected to be the arguments. Only for queries you can omit the arguments by only using two arguments.

$this->mutation('logout', ['status', 'message']);

This results in this query:

mutation {
   logout(0: 'status', 1: 'message')
}

What you want to do is this:

$this->mutation('logout', [], ['status', 'message']);

Which results in this:

mutation {
   logout {
      status
      message
   }
}

See this table for correct argument order:

Method Arguments Result
query (object) GraphQLClient
query (object, selectionSet) TestResponse
query (object, arguments, selectionSet) TestResponse
mutation (object) GraphQLClient
mutation (object, arguments) TestResponse
mutation (object, arguments, selectionSet) TestResponse

@marvinrabe marvinrabe added the question Further information is requested label Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants