- Can I use wyrihaximus/test-utilities with Laravel’s default PHPUnit 10.x setup?
- No, this package requires PHPUnit 12.x, which conflicts with Laravel’s default. Mitigate this by adding a `replace` directive in your `composer.json` to force PHPUnit 10.x compatibility or use Laravel’s `phpunit.php` config to override test runner settings. Test thoroughly, as some Laravel test helpers may break.
- How do the random directories in this package interact with Laravel’s storage paths?
- The package generates random directories for file-based tests, which could conflict with Laravel’s `storage/` or `public/` paths. Whitelist safe paths in the `TestCase` or override defaults to avoid issues with `storage:link` or file uploads. Always test file operations in isolation.
- Will this package’s Rector rules break Laravel’s migration tooling?
- Potential conflicts exist if Laravel uses Rector for migrations (e.g., Laravel 10+). Scope the package’s `RectorConfig` to tests only by running Rector via `vendor/bin/rector-process` in a dedicated test environment. Avoid applying it globally to your project.
- Can I integrate this with Pest instead of PHPUnit?
- Yes, but indirectly. The package’s `TestCase` base class is PHPUnit-specific, but you can adapt its utilities (e.g., random namespaces) by creating a Pest plugin or custom trait. Use Pest’s `extend()` method to incorporate shared logic like temp directory handling.
- How do I configure PHPStan extensions for Laravel-specific rules?
- The package provides PHPStan extension defaults, but you may need to merge them with Laravel’s `phpstan.neon`. Start by including the package’s config and resolve conflicts by explicitly defining Laravel-specific rules (e.g., `@mixin` for traits) in your project’s PHPStan config.
- Does this package support API testing for Laravel HTTP clients (e.g., Guzzle)?
- Yes, it’s designed for API client testing. The `TestCase` includes helpers for randomized test data, mocking, and file storage, which are useful for testing Laravel HTTP clients. Pair it with Laravel’s `Http::fake()` or `Mockery` for full API test coverage.
- How do I avoid slow tests in Laravel when using phpunit-slow-test-detector?
- The package includes a slow-test detector, but Laravel’s parallel testing or CI timeouts may interfere. Configure the detector’s threshold in `phpunit.xml` and exclude known slow tests (e.g., database-heavy tests) using annotations like `@group slow`. Monitor CI feedback to adjust thresholds.
- What’s the best way to migrate legacy docblocks to attributes in a Laravel project?
- Use the package’s `RectorConfig` to convert docblocks to attributes, but run it in a staging environment first. For Laravel-specific attributes (e.g., `@mixin`), extend the config to include custom rules. Test thoroughly, as breaking changes may affect IDE autocompletion or static analysis.
- Are there alternatives to this package for Laravel testing?
- For Laravel-specific testing, consider `laravel/testbench` (for legacy packages) or `mockery` for mocking. For modern PHP practices, `rector/rector` and `phpstan/phpstan` can be used standalone. This package excels for API clients and static analysis but requires extra effort for Laravel integration.
- How do I ensure test isolation when using random namespaces in Laravel?
- The `TestCase` generates random namespaces, but Laravel’s autoloader may conflict with dynamic class names. Use fully qualified namespaces in tests and avoid dynamic class generation for Eloquent models. For file-based tests, combine with Laravel’s `Storage::fake()` to isolate storage operations.