- Can I use wp-cli/wp-cli-tests for Laravel-based WordPress plugins or themes?
- Yes, but with adjustments. The framework is designed for WP-CLI projects, so for Laravel-WP hybrids, you’ll need to mock WordPress dependencies or use WP-CLI’s `--path` flag to point to a sandboxed WordPress instance. Behat tests may require custom Laravel-specific contexts to interact with Eloquent or Artisan.
- How do I install wp-cli/wp-cli-tests in a Laravel project?
- Run `composer require --dev wp-cli/wp-cli-tests` to add it as a dev dependency. Then configure your `composer.json` scripts (e.g., `phpunit`, `behat`) as shown in the package’s README. Laravel’s existing PHPUnit setup will work, but Behat requires WordPress-specific contexts.
- Will this conflict with Laravel’s built-in testing tools like Pest or Dusk?
- No direct conflict, but Behat tests assume a WP-CLI environment. For Laravel-WP hybrids, run Behat tests separately or integrate them into CI as a distinct stage. PHPUnit and PHPCS tests can coexist with Laravel’s toolchain by merging rulesets (e.g., `laravel-shift/php-code-style` + WP-CLI standards).
- Does wp-cli/wp-cli-tests support Laravel’s Eloquent ORM or database migrations?
- No, the framework is WordPress-centric. For Eloquent or Laravel migrations, use Laravel’s native testing tools (e.g., `DatabaseMigrations`, `DatabaseTransactions`). Behat tests default to WordPress databases, so use environment variables like `WP_CLI_TEST_DBTYPE=sqlite` or Dockerized WordPress instances to avoid conflicts.
- How do I configure Behat for cross-platform testing in a Laravel project?
- Add a `behat.yml` file with the default `FeatureContext` from the package. For Laravel-WP hybrids, extend the context to include Laravel services (e.g., `setMockServiceContainer()`). The package provides a cross-platform template, but ensure your CI environment (e.g., GitHub Actions, Docker) supports WordPress installations.
- What Laravel versions are compatible with wp-cli/wp-cli-tests?
- The package itself is Laravel-agnostic, but functional tests (Behat) require WordPress core. For Laravel 8/9/10, use WP-CLI’s `--path` flag to target a WordPress install alongside Laravel. Avoid routing conflicts by sandboxing WordPress (e.g., Docker) or using Laravel’s service container to mock WP-CLI interactions.
- Can I skip Behat tests if I only need unit testing for Laravel-WP CLI commands?
- Yes, remove the `behat` script from `composer.json` and omit the `behat.yml` file. Focus on PHPUnit for unit tests and PHPCS for linting. This reduces overhead for projects where functional WP-CLI tests aren’t critical, but ensure your Laravel-WP CLI commands are tested via Artisan or custom PHPUnit test cases.
- How do I handle database seeding in CI when using both Laravel and WP-CLI tests?
- Run Laravel’s `DatabaseSeeder` separately from WP-CLI tests. Use environment variables to isolate databases (e.g., `WP_CLI_TEST_DB=wp_test` for Behat, `DB_DATABASE=laravel_test` for Laravel). For CI, structure your pipeline to run Laravel migrations first, then Behat tests against a fresh WordPress install.
- Are there alternatives to wp-cli/wp-cli-tests for Laravel-WP CLI testing?
- For pure Laravel testing, use Pest or Laravel Dusk. For WP-CLI, alternatives include custom PHPUnit setups with `wp-cli/wp-cli` or `brain-monkey/wp-cli-parallel-tests`. However, `wp-cli/wp-cli-tests` is the most comprehensive for WP-CLI-specific tooling (Behat, PHPCS) and integrates well with Laravel’s Composer workflow.
- How do I debug failures in Behat tests for a Laravel-WP hybrid project?
- Start by checking WordPress-specific errors (e.g., missing plugins, database issues). For Laravel conflicts, inspect the `FeatureContext` for unhandled service dependencies. Use `WP_CLI_DEBUG=1` and Laravel’s `--verbose` flag to trace interactions. Isolate the issue by running Behat tests against a minimal WordPress install (e.g., Docker) without Laravel.