PHPackages                             zestic/pest-plugin-graphql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. zestic/pest-plugin-graphql

ActiveLibrary[Framework](/categories/framework)

zestic/pest-plugin-graphql
==========================

Test your PHP GraphQL server in style, with Pest!

v0.1.0(2y ago)02MITPHPPHP ^8.1

Since Jan 7Pushed 2y agoCompare

[ Source](https://github.com/zestic/pest-plugin-graphql)[ Packagist](https://packagist.org/packages/zestic/pest-plugin-graphql)[ GitHub Sponsors](https://github.com/miniaturebase)[ Patreon](https://www.patreon.com/minibase)[ RSS](/packages/zestic-pest-plugin-graphql/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Pest GraphQL Plugin
===================

[](#pest-graphql-plugin)

Test your GraphQL API in style, with Pest!

Installation
------------

[](#installation)

Simply install through Composer!

```
composer require --dev zestic/pest-plugin-graphql
```

In your `.env` file, set the testing url

```
TEST_GRAPHQL_URL=http://localhost
```

To organize your tests, create an `Api` directory in your `tests` directory.

Make sure your namespace is set up correctly in the `composer.json` file.

```
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    }
```

Finally, in your Pest.php file add the following line:

```
 uses(Pest\GraphQl\ApiTestCase::class)->in('Api');
```

What's Added?
-------------

[](#whats-added)

- Test your schema as code;
- Assert PSR-7 GraphQL response data *and* errors;
- Testing resolvers *(Coming Soon!)*;

### Expectations

[](#expectations)

- `schema(string|Schema $document)`
- `isValidSdl()`
- `toHaveDirective(string $directive)`
- `toHaveEnum(string $enum)`
- `toHaveInput(string $input)`
- `toHaveInterface(string $interface)`
- `toHaveScalar(string $scalar)`
- `toHaveType(string $type)`
- `toHaveUnion(string $union)`
- `toBeGraphQlResponse()`
- `toHavePath(string $path, $value = null)`
- `toHaveData(array $data)`
- `toHaveErrors(array $errors)`

And more on the way!

#### `schema(string|Schema $document)`

[](#schemastringschema-document)

Create a new expectation with a `GraphQL\Type\Schema` instance as the underlying value.

```
test('my schema')->schema();
it('is my schema')->schema();
Pest\GraphQl\schema();
```

You can also provide an alternative schema path or document contents, like so.

```
it('uses any schema you want')->schema(sprintf('%s/../app/schema.graphql', __DIR__));
test('inline content')->schema(schema(AcmeSchemaBuilder::build());
```

#### `isValidSdl()`

[](#isvalidsdl)

Assert that the schema is valid and written to the GraphQL specification.

```
it('validates your schema')->schema()->isValidSdl();
```

#### `toHaveDirective(string $directive)`

[](#tohavedirectivestring-directive)

Assert that the given directive definition exists with the schema document.

```
it('has a directive')->schema()->toHaveDirective('auth')
it('will also use base classnames')->schema()->toHaveDirective(Auth::class);
```

#### `toHaveEnum(string $enum)`

[](#tohaveenumstring-enum)

Assert that the given enum definition exists with the schema document.

```
it('has an enum')->schema()->toHaveEnum('Status')
it('will also use base classnames')->schema()->toHaveEnum(Status::class);
```

#### `toHaveInput(string $input)`

[](#tohaveinputstring-input)

Assert that the given input definition exists with the schema document.

```
it('has a input')->schema()->toHaveInput('Message')
it('will also use base classnames')->schema()->toHaveInput(Message::class);
```

#### `toHaveInterface(string $interface)`

[](#tohaveinterfacestring-interface)

Assert that the given interface definition exists with the schema document.

```
it('has a interface')->schema()->toHaveInterface('Notification')
it('will also use base classnames')->schema()->toHaveInterface(Notification::class);
```

#### `toHaveScalar(string $scalar)`

[](#tohavescalarstring-scalar)

Assert that the given scalar definition exists with the schema document.

```
it('has a scalar')->schema()->toHaveScalar('Date')
it('will also use base classnames')->schema()->toHaveScalar(Date::class);
```

#### `toHaveType(string $type)`

[](#tohavetypestring-type)

Assert that the given (object) type has been defined within the schema document.

```
it('has mutations')->schema()->toHaveType('Mutation');
test('user defined types too')->schema()->toHaveType('User');
it('will also use your base classnames')->schema()->toHaveType(User::class);
```

#### `toHaveUnion(string $union)`

[](#tohaveunionstring-union)

Assert that the given union definition exists with the schema document.

```
it('has a union')->schema()->toHaveUnion('Character')
it('will also use your base classnames')->schema()->toHaveUnion(Character::class);
```

#### `toBeGraphQlResponse()`

[](#tobegraphqlresponse)

Assert that an underlying (PSR-7) response value is a compliant with the GraphQL specification.

```
test('response validity')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toBeGraphQlResponse();
```

#### `toHavePath(string $path, $value = null)`

[](#tohavepathstring-path-value--null)

Assert that the underlying GraphQL response contains data at the given path. Optionally provide a value to be checked as well!

```
it('reads paths')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHavePath('foo')
    ->toHavePath('foo', 1)
    ->not()
    ->toHavePath('foo.bar')
    ->not()
    ->toHavePath('foo', 0);
```

#### `toHaveData(array $data)`

[](#tohavedataarray-data)

Assert that the underlying response GraphQL data is canonically equal to the expected data.

```
it('contains response data')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHaveData([
        'foo' => 1,
    ]);
```

#### `toHaveErrors(array $errors)`

[](#tohaveerrorsarray-errors)

Assert that the underlying response GraphQL errors are canonically equal to the expected set of errors.

```
it('has errors')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHaveErrors([
        [
            'message'   => 'Oops, I did it again',
            'locations' => [['line' => 1, 'column' => 5]],
            'path'      => ['foo'],
        ],
    ]);
```

---

This repository was based off of the Pest Plugin Template.

Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

855d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd5a2c6deedf2f52379d21fa55c9f5c6d0999b0ac1ca2ca2f33293e229107bfe?d=identicon)[iampersistent](/maintainers/iampersistent)

---

Top Contributors

[![jordanbrauer](https://avatars.githubusercontent.com/u/18744334?v=4)](https://github.com/jordanbrauer "jordanbrauer (15 commits)")

---

Tags

phpplugintestingunitframeworktestpestgraphql

### Embed Badge

![Health badge](/badges/zestic-pest-plugin-graphql/health.svg)

```
[![Health](https://phpackages.com/badges/zestic-pest-plugin-graphql/health.svg)](https://phpackages.com/packages/zestic-pest-plugin-graphql)
```

###  Alternatives

[defstudio/pest-plugin-laravel-expectations

A plugin to add laravel tailored expectations to Pest

98548.9k4](/packages/defstudio-pest-plugin-laravel-expectations)[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)[jonpurvis/lawman

A PestPHP Plugin to help with architecture testing SaloonPHP integrations

4027.7k8](/packages/jonpurvis-lawman)[spatie/pest-plugin-route-testing

Make sure all routes in your Laravel app are ok

13753.8k](/packages/spatie-pest-plugin-route-testing)[milroyfraser/pest-plugin-gwt

Given When Then(GWT) Plugin for Pest

10332.1k1](/packages/milroyfraser-pest-plugin-gwt)[ozzie/pest-plugin-nest

Nest Pest PHP tests for better organization and readability

2028.3k](/packages/ozzie-pest-plugin-nest)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
