Skip to content

Commit

Permalink
Add the possibility to get the original HttpResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
kauanslr committed Apr 26, 2019
1 parent c437fea commit 28ad18c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,33 @@ class TestMyGraphQL extends TestCase
$this->assertGraphQLFields($fields);
}
}
```

Também é possível utilizar as respostas utilizando a interface padrão do Laravel:

```php
use Kauanslr\GraphThing\Traits\MakeGraphQLRequests;

class TestMyGraphQL extends TestCase
{
use MakeGraphQLRequests;

/** @var Endpoint */
protected $endpoint = '/your_graphql_endpoint' //Default '/graphql';

public function test_my_first_mutation_endpoint() {
// Parametros para mutação
$params = [];

// Campos para serem retornados
$query = ['field_1'];

// Campos retornados pela query
$fields = $this->graphqlMutate('mutationName', $params, $query);

// Retorna uma instancia de \Illuminate\Foundation\Testing\TestResponse
$response = $this->graphql->getResponse();
$response->assertStatusCode(403);
}
}
```
10 changes: 10 additions & 0 deletions src/GraphThing/LaravelTestGraphQLClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function __construct(Application $app, string $baseUrl)
$this->app = $app;
}

/**
* Return the request response object.
*
* @return \Illuminate\Http\Response|\Illuminate\Foundation\Testing\TestResponse
*/
public function getResponse()
{
return $this->response;
}

protected function postQuery(array $data): array
{
$this->response = $this->post($this->getBaseUrl(), $data, $this->getHeaders());
Expand Down

0 comments on commit 28ad18c

Please sign in to comment.