lastdragon-ru/lara-asp-graphql-testing
Testing helpers for GraphQL in Laravel apps using lara-asp. Provides utilities and assertions to build requests, execute queries/mutations, and validate responses in automated tests, making GraphQL endpoint testing faster and more reliable.
assertGraphQLSchemaEqualsCompares default internal schema (with all directives).
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\GraphQL\Testing\Docs\Assertions;
use LastDragon_ru\LaraASP\Core\PackageProvider as CorePackageProvider;
use LastDragon_ru\LaraASP\GraphQL\PackageProvider as GraphQLPackageProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Assertions;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Provider as TestProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestDirective;
use LastDragon_ru\LaraASP\Testing\Testing\TestCase;
use Nuwave\Lighthouse\LighthouseServiceProvider;
use Nuwave\Lighthouse\Schema\DirectiveLocator;
use Override;
use PHPUnit\Framework\Attributes\CoversNothing;
use function array_merge;
/**
* [@internal](https://github.com/internal)
*/
#[CoversNothing]
final class AssertGraphQLSchemaEqualsTest extends TestCase {
/**
* Trait where assertion defined.
*/
use Assertions;
/**
* Preparation for test.
*/
#[Override]
protected function getPackageProviders(mixed $app): array {
return array_merge(parent::getPackageProviders($app), [
TestProvider::class,
CorePackageProvider::class,
GraphQLPackageProvider::class,
LighthouseServiceProvider::class,
]);
}
/**
* Assertion test.
*/
public function testAssertion(): void {
// Prepare
$this->app()->make(DirectiveLocator::class)
->setResolved('a', TestDirective::class)
->setResolved('test', TestDirective::class);
$this->useGraphQLSchema(
<<<'GRAPHQL'
directive [@a](https://github.com/a)(b: B) on OBJECT
type Query {
a: A [@test](https://github.com/test)
}
type A [@a](https://github.com/a) {
id: ID!
}
input B {
b: String!
}
GRAPHQL,
);
// Test
$this->assertGraphQLSchemaEquals(
<<<'GRAPHQL'
directive [@a](https://github.com/a)(
b: B
)
on
| OBJECT
directive [@test](https://github.com/test)
on
| FIELD_DEFINITION
input B {
b: String!
}
type A
[@a](https://github.com/a)
{
id: ID!
}
type Query {
a: A
[@test](https://github.com/test)
}
GRAPHQL,
);
}
}
How can I help you explore Laravel packages today?