cjweber/laravel-test-graphql-client
Composer 安装命令:
composer require --dev cjweber/laravel-test-graphql-client
包简介
Client and TestCase extension for running integration tests on requests to your GraphQL API
README 文档
README
This is a package which allows you to create integration tests against your GraphQL API easily and quickly.
Requirements
1. Laravel 6.0 + / PHP 7.0 +
2. PHPUnit 8.0 +
3. GraphQL setup on your Laravel server, via https://github.com/rebing/graphql-laravel or other
What's inside
1. Basic GraphQL Client
2. Extension of TestCase which allows for access to the GraphQL client within your tests
Installation
composer require cjweber/laravel-test-graphql-client --dev
Usage
1. Extend the package TestCase for your feature test in order to leverage the included GraphQL Client
2. Make queries against your GraphQL by constructing a Query object and then passing it to the `graphql` property on your TestCase class
3. Use the `assertGraphQlFields` function in the package to test that the server returned the fields you expect. You can also do any other assertions that come with PHPUnit against the response data returned by the client.
Example
<?php
namespace Tests\Feature\GraphQL;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use GraphQLTestClient\TestCase;
use GraphQLTestClient\Field;
use GraphQLTestClient\Query;
use App\Project;
use App\User;
class ProjectTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function setUp() :void
{
parent::setUp();
$this->user = factory(User::class)->create();
}
/**
* Test that a User can create a Project
*
* @return void
*/
public function testCreateProject()
{
$this->actingAs($this->user, 'api');
$description = $this->faker->paragraph;
$name = $this->faker->sentence;
$query = new Query(
'project',
[
'input' => [
'name' => $name,
'description' => $description,
],
],
[
new Field('uuid'),
new Field('description'),
new Field('name'),
]
);
$result = $this->graphql->mutate($query)->getData();
$this->graphql->assertGraphQlFields($result, $query);
$createdProject = Project::where('uuid', $result['uuid'])->first();
$this->assertEquals($createdProject->name, $name);
$this->assertEquals($createdProject->description, $description);
$this->assertEquals($result['name'], $name);
$this->assertEquals($result['description'], $description);
}
}
Thanks
Christian Goltz for providing the much of the base GraphQL client code in https://github.com/christiangoltz/graphql-client-php
Feedback / Changes
Feel free to email me at christopher.j.weber@protonmail.com , create an issue, and/or submit a PR if you want to make any improvements or changes.
cjweber/laravel-test-graphql-client 适用场景与选型建议
cjweber/laravel-test-graphql-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.37k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「client」 「laravel」 「graphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cjweber/laravel-test-graphql-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cjweber/laravel-test-graphql-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cjweber/laravel-test-graphql-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
统计信息
- 总下载量: 6.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-08-10