kauanslr / graphthing
此包已被废弃,不再维护。未建议替代包。
测试您的 graphql 查询和突变时,让您的生命更轻松
0.3.0
2019-04-26 17:55 UTC
Requires
- php: ^7.0
Requires (Dev)
- laravel/framework: >=5.5
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2022-03-06 17:54:53 UTC
README
安装 - PT-BR
Composer
要安装,请将以下代码添加到您的 composer.json
{ "require": { "kauanslr/graphthing": "^0" } }
然后执行 $ composer update
或者只需执行 $ composer require --dev kauanslr/graphthing
使用
支持外部端点
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 = [ 'field' => 'My first endpoint test', ]; // Campos para serem retornados $query = ['field_1','field_2', 'field_3']; // Campos retornados pela query $fields = $this->graphqlMutate('mutationName', $params, $query); // Verifica se todos os campos solicitados foram retornados $this->assertGraphQLFields($fields); } public function test_my_sub_queries_endpoint() { // Os parâmetros para a query principal $queryParams = []; // Campos para serem retornados $query = [ 'field_1', 'field_2', 'subQueryName' => [ 'params' => [ 'sub_query_param' => 'value' ], 'sub_field_1', 'sub_field_2', 'sub_field_3', ] ]; // Campos retornados pela query $fields = $this->graphqlQuery('queryName', $params, $query, $headers); // Verifica se todos os campos solicitados foram retornados $this->assertGraphQLFields($fields); } }
也可以使用 Laravel 的标准接口进行请求测试
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); } }
安装 - EN
Composer
只需将以下代码添加到您的 composer.json
{ "require": { "kauanslr/graphthing": "^0" } }
然后运行 $ composer update
或者只需运行 $ composer require --dev kauanslr/graphthing
使用
支持外部端点
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() { // MUtation parameters $params = [ 'field' => 'My first endpoint test', ]; // To return fields $query = ['field_1','field_2', 'field_3']; // Get the query result $fields = $this->graphqlMutate('mutationName', $params, $query); // Check if requested fields is was returned $this->assertGraphQLFields($fields); } public function test_my_sub_queries_endpoint() { // Principal query parameters $queryParams = []; // Requesting fields $query = [ 'field_1', 'field_2', 'subQueryName' => [ 'params' => [ 'sub_query_param' => 'value' ], 'sub_field_1', 'sub_field_2', 'sub_field_3', ] ]; // Get query results $fields = $this->graphqlQuery('queryName', $params, $query, $headers); // Check if requested fields is was returned $this->assertGraphQLFields($fields); } }
还可以使用 Laravel 的请求测试接口
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() { // Mutation parameters $params = []; // Query fields $query = ['field_1']; // Execute mutation $fields = $this->graphqlMutate('mutationName', $params, $query); //Reutur \Illuminate\Foundation\Testing\TestResponse instance $response = $this->graphql->getResponse(); $response->assertStatusCode(403); } }