- What is noeldemartin/laravel-dusk-mocking used for?
- It lets you mock classes, services, and facades inside Laravel Dusk browser tests. Dusk runs the browser in a separate process, so ordinary PHPUnit mocks created in the test process cannot reach the application under test. This package registers mocks in your Dusk test and applies them inside the application, making end-to-end tests faster and more predictable.
- How do I install laravel-dusk-mocking in a Laravel project?
- Install it as a dev dependency with Composer using composer require noeldemartin/laravel-dusk-mocking --dev. It belongs in your test tooling, not in production dependencies. After installation, confirm the package version constraints match your Laravel and Dusk versions in composer.json.
- How do I mock a facade in a Laravel Dusk test?
- Register the facade or service you want to replace using the package's mocking helpers before the Dusk browser test runs. The package then makes that mock available to the application process that Dusk drives. Use the same facade API your application normally uses so the test exercises realistic call paths.
- Does laravel-dusk-mocking work with PHPUnit and Pest?
- Yes, it is designed to fit standard Laravel test suites, including PHPUnit and Pest-based Dusk tests. You still write and run Dusk browser tests as usual; the package only changes how mocks are registered and applied across the Dusk process boundary. Check your test runner configuration if you use custom Dusk setup.
- Which Laravel and PHP versions does laravel-dusk-mocking support?
- Exact Laravel and PHP constraints are defined in the package's composer.json, so verify them before upgrading. The current v6.x line follows Laravel Dusk's supported stack, and v6.5.3 is a patch release that should be backward compatible for existing v6 users. Run a normal Composer update and your test suite to confirm compatibility.
- Can I mock HTTP calls in Laravel Dusk tests with this package?
- The v6.5.3 patch adds an HTTP Client fake, aligning with Laravel's Http::fake() testing conventions. This helps you stub outbound HTTP calls so Dusk tests do not depend on live network services. Confirm which HTTP abstraction and error paths are covered in your version, and keep fakes aligned with real API contracts.
- How is laravel-dusk-mocking different from Laravel's built-in fakes?
- Laravel's built-in fakes work inside the application test process, but Dusk drives a separate browser process, so those fakes do not automatically reach the application. laravel-dusk-mocking bridges that gap by registering mocks that are applied in the application during the Dusk test. It complements rather than replaces Laravel's native testing helpers.
- Do mocks leak between Laravel Dusk tests?
- The intended pattern is to register mocks per test, which limits cross-test leakage. However, any global bindings or suite-wide configuration can still affect unrelated tests, so reset custom state between tests. Review test isolation in CI, especially when replacing widely used facades or services.
- Is laravel-dusk-mocking safe to use in production?
- It is a test-only package and should be installed as a dev dependency, not enabled in production. It does not change runtime behavior unless mocks are registered in a test context. Keep it out of production deployments and avoid exposing test-only configuration in live environments.
- What are alternatives to laravel-dusk-mocking for Dusk tests?
- Alternatives include using a local stub HTTP server, exposing test-only routes or configuration, or injecting fake services through the application container before Dusk starts. Laravel's native fakes are excellent for application tests but do not cross Dusk's process boundary on their own. laravel-dusk-mocking is aimed at developers who want facade and service mocks directly inside Dusk browser tests.