Open sandervanhooft opened 7 years ago
I would also like to know this.
If you look at the feature/relay branch, some tests kind of does this
Is there a way now to do this? Because i couldn't find anything on the feature/relay branch
Haven't encountered a viable way yet. Let me know if you find anything :)
Well i copied some things from graphql php library and build something my own.
Its simple and maybe not the best way but it works. So first i created a new base testcase class
abstract class GraphQLTestCase extends TestCase {
protected $queries;
protected $mutations;
protected $data;
public function setUp() {
parent::setUp();
$this->queries = include(__DIR__ . '/fixtures/GraphQL/queries.php');
$this->mutations = include(__DIR__ . '/fixtures/GraphQL/mutations.php');
}
protected function graphQlUri($query, $prefix = '') {
return '/graphql/' . $prefix . '?query=' . urlencode($query);
}
}
Under fixtures/GraphQL` i got two files with just queries or mutations looking like this (mutation example):
'cancelAppointment' => function ($id) {
return '
mutation {
appointment: cancelAppointment(input: {
id: ' . $id . ',
}) { status }
}
';
}
Than test looks like this:
$response = $this->get($this->graphQlUri($this->mutations['cancelAppointment']($appointment->id), 'some_prefix_if-you_use'));
$content = $response->getData(true);
$content = $content['data'];
$this->assertEquals('canceled', $content['appointment']['status']);
I'd like to take a TDD approach on implementing a schema. Do you have a recommended way to (or an example repo) write phpunit tests for testing queries and mutations?