- What is php-mock/php-mock-prophecy used for?
- It is a test-only integration that lets you replace built-in PHP functions such as time(), uniqid(), and sleep() with Prophecy doubles. It is useful when legacy or procedural code calls global functions directly and you cannot easily inject a clock or service. It is not an application runtime package and should be installed as a dev dependency.
- Is php-mock/php-mock-prophecy suitable for Laravel applications?
- Not as a default choice. Laravel teams usually use PHPUnit or Pest with Mockery, Laravel test helpers, or injectable dependencies. This package makes sense only if your Laravel test suite already uses Prophecy and has unavoidable global-function mocking needs. Treat it as a narrow compatibility shim for legacy tests.
- How do I install php-mock/php-mock-prophecy in a Laravel project?
- Install it with Composer as a dev dependency, for example composer require --dev php-mock/php-mock-prophecy. You also need Prophecy available in the test environment and should confirm that php-mock resolves correctly with your PHP version. Then configure namespaced function mocking in the specific tests that need it.
- Do I need Prophecy to use php-mock/php-mock-prophecy?
- Yes. This package is explicitly the Prophecy integration for php-mock, so Prophecy must be installed and used by the tests. If your suite standardizes on Mockery or Laravel's built-in fakes, this package is not the right fit. Adding Prophecy just for one test is usually not worth the extra dependency.
- Which PHP and Laravel versions are supported by php-mock/php-mock-prophecy?
- The provided context does not list exact supported PHP, Laravel, or Prophecy versions, so verify Composer constraints in a clean install. Test against your real CI matrix before adopting it. Do not assume Laravel version support; the package is framework-agnostic and compatibility depends on PHP and Prophecy versions.
- Can php-mock/php-mock-prophecy mock functions like time(), sleep(), or uniqid()?
- Yes, its purpose is mocking built-in PHP functions, with time(), uniqid(), and sleep() as common examples. You define Prophecy prophecies for the native calls and can use promises and predictions. Function mocking normally requires namespaced test code or bootstrap configuration so calls resolve to the mocked function.
- Does php-mock/php-mock-prophecy work with PHPUnit and Pest?
- It can work with PHPUnit when Prophecy and the necessary PHPUnit-Prophecy bridge are present. Pest may work through the same underlying stack but is not a primary target described here. Verify with a small pilot test in your actual runner before rolling it out.
- Is php-mock/php-mock-prophecy safe to use with parallel test execution?
- Parallel test execution is a real risk because function mocking can leak across tests or processes. The assessment recommends validating parallel runs carefully and keeping usage narrowly scoped. If your suite runs in parallel, isolate these tests or avoid the package unless proven safe.
- What are alternatives to php-mock/php-mock-prophecy for mocking built-in functions?
- Prefer refactoring to injectable clocks, gateways, or service abstractions so tests do not need global function mocking. Alternatives include a small internal test helper, php-mock with other integrations, or PHPUnit-specific function mocking tools. Choose an alternative that matches your existing Mockery, PHPUnit, or Pest stack.
- How risky is depending on php-mock/php-mock-prophecy in a Laravel project?
- Production risk is low because this is a require-dev, test-only utility and should not ship at runtime. The real risk is test-suite fragility, version conflicts, low adoption, unknown repository provenance, long-term maintenance, and a WTFPL license that may need legal review. Use it only after a time-boxed CI pilot and keep it out of new code where dependency injection is possible.