- How do I install this package for Laravel GraphQL testing?
- Run `composer require lastdragon-ru/phpunit-graphql` and ensure `lastdragon-ru/graphql-printer` is installed. The package integrates directly with PHPUnit, so no additional Laravel configuration is needed beyond your existing test setup.
- Does this package work with Laravel’s built-in PHPUnit?
- Yes, it’s fully compatible with Laravel’s PHPUnit integration. You can use it alongside Laravel’s testing helpers like `actingAs()` or `refreshDatabase()` in your GraphQL test cases.
- Which Laravel GraphQL packages does this support (e.g., webonyx/graphql-php, filamentphp/graphql)?
- This package works with any PHP GraphQL implementation that uses `lastdragon-ru/graphql-printer` for output formatting. If your Laravel app uses a different printer (e.g., webonyx’s default), you may need to adapt or switch printers.
- Can I test GraphQL mutations and subscriptions with this package?
- Yes, the assertions support mutations and subscriptions, but you’ll need to structure your test cases to match the printer’s output format. For subscriptions, ensure your test environment can handle real-time responses.
- What happens if my GraphQL schema evolves (e.g., new fields or deprecations)?
- Assertions tied to specific schema structures may need updates. Test critical queries early and refactor assertions incrementally to match schema changes. The package doesn’t lock you into a schema version.
- Is there a performance impact when running these assertions in CI/CD?
- The package adds minimal overhead since it focuses on parsing and validating printer output. For large schemas, ensure your CI environment has sufficient resources, but it should not significantly slow down test execution.
- How do I handle errors or invalid responses in GraphQL tests?
- The package provides utilities to validate error structures, including error messages and codes. Use assertions like `assertGraphQLErrorMatches()` to verify expected failures in queries or mutations.
- What if I don’t want to use `lastdragon-ru/graphql-printer`? Are there alternatives?
- This package is designed to work with `graphql-printer`. If you’re using a different printer (e.g., webonyx’s default), you’ll need to either switch printers or create custom assertion wrappers to match your output format.
- Can I extend or customize the assertions for my Laravel app?
- Yes, the package is designed for extensibility. You can create custom assertion methods or wrappers to handle edge cases, such as validating complex fragments or directives specific to your GraphQL schema.
- What Laravel and PHPUnit versions does this package support?
- The package aligns with Laravel’s PHPUnit version (typically ^9.5 or ^10.0). Check the package’s `composer.json` for exact requirements, but it should work seamlessly with modern Laravel setups using PHPUnit.