PHP code example of cjweber / laravel-test-graphql-client
1. Go to this page and download the library: Download cjweber/laravel-test-graphql-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cjweber / laravel-test-graphql-client example snippets
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);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.