- How do I install this package for Laravel GraphQL testing?
- Run `composer require --dev lastdragon-ru/lara-asp-graphql-testing` in your project. It’s designed for development use only and requires PHP 8.3–8.5 and PHPUnit 11.2–13. Ensure you’re using `lastdragon-ru/lara-asp-graphql` as your GraphQL layer.
- Which Laravel versions does this package support?
- This package is framework-agnostic but requires PHP 8.3–8.5 and PHPUnit 11.2–13. It’s compatible with any Laravel version that supports these PHP/PHPUnit constraints, as it integrates via PHPUnit assertions. No Laravel-specific dependencies exist.
- Can I use this package with Pest instead of PHPUnit?
- No, this package is built for PHPUnit only. If you use Pest, you’d need to manually adapt the assertions or explore alternatives like `spatie/laravel-graphql-testing`, which may offer broader framework support.
- What assertions are available for GraphQL schema validation?
- The package provides `assertGraphQLIntrospectionEquals` (client-facing schema), `assertGraphQLSchemaEquals` (internal schema), and `assertGraphQLSchemaNoBreakingChanges` (schema regression testing). These help validate schema structure, directives, and backward compatibility.
- How do I test GraphQL queries and mutations with this package?
- Extend your test class with the `Assertions` trait and use methods like `assertQueryReturnsFields` or `assertMutationReturnsData`. Example: `$this->assertQueryReturnsFields($response, ['user' => ['id', 'name']])`. It works with `lara-asp-graphql`’s response objects.
- Does this package support testing GraphQL subscriptions?
- No, the package currently focuses on queries and mutations. Subscriptions require real-time testing (e.g., WebSocket connections), which isn’t covered. For subscriptions, consider manual testing or tools like Laravel Echo or custom event listeners.
- How do I handle authentication in GraphQL tests with this package?
- This package doesn’t include auth-specific assertions. Use Laravel’s built-in auth helpers (e.g., `actingAs`) or middleware in your test setup. For GraphQL auth (e.g., `@auth` directives), manually validate token headers or roles in your test responses.
- What if my GraphQL schema is dynamic (e.g., generated via ORM)?
- The package works best with static schemas (SDL-first). For dynamic schemas, you may need custom assertions to validate runtime-generated types or fields. Document your schema’s behavior and extend the package’s assertions as needed.
- Are there alternatives to this package for Laravel GraphQL testing?
- Yes, consider `graphql-php/graphql-testing` (language-agnostic) or `spatie/laravel-graphql-testing` (Laravel-focused). These may offer broader compatibility, especially if you’re not using `lara-asp-graphql`. Evaluate based on your GraphQL layer and testing needs.
- How do I integrate this into CI/CD pipelines?
- Add the package to your `composer.json` dev dependencies and run PHPUnit tests as usual. The assertions add minimal overhead and integrate seamlessly with Laravel’s test suite. Monitor test coverage for schema changes to catch breaking updates early.