php-mock/php-mock-prophecy
Prophecy integration for php-mock lets you mock PHP built-in functions like time, rand, and sleep inside Prophecy test doubles. Define expected behavior for global functions alongside class mocks, making time-dependent code testable without hard dependencies.
Architecture fit: This is a test-only utility, not an application runtime dependency. It fits only where the codebase uses Prophecy/phpspec-style mocking and needs to replace built-in PHP functions such as time(), sleep(), or similar global calls in legacy or procedural code. It is not a natural fit for a standard Laravel stack, which typically standardizes on PHPUnit/Pest with Mockery or Laravel’s own test helpers. It should not influence production architecture.
Integration feasibility: Feasible as a Composer require-dev dependency if the project already has Prophecy installed and has test cases that cannot be refactored to inject clocks, gateways, or service abstractions. Integration is likely low-code: add the package, configure namespaced function mocking, and use it in narrowly scoped tests. Feasibility drops sharply if the team is not already using Prophecy or if tests rely on parallel execution.
Technical risk: Moderate to high for a dependency decision. The package has very low visible adoption (16 stars), an unknown repository, and a permissive but no-warranty license (WTFPL). The last release date is recent, but provenance and maintainer continuity are unverified. The technical risk is not production outage risk because this is test-only; the real risk is test-suite fragility, version conflicts, and long-term maintainability. The low score suggests limited ecosystem validation.
Key questions:
Stack fit: Treat this as a narrow compatibility shim for legacy tests, not a platform component. It fits best in a PHP project already using Prophecy where global PHP function calls are common. It does not fit as a default Laravel dependency and should not be added unless a specific test suite proves the need.
Migration path: Start with a disposable pilot branch. Add the package under require-dev, write one or two tests that mock time() or another built-in function, and verify behavior under the project’s real CI matrix. If successful, keep usage confined to legacy test namespaces. Prefer refactoring new code toward injected clocks/services rather than expanding function-mocking coverage.
Compatibility: Validate against the exact PHP version, Prophecy version, php-mock dependency graph, and test runner in use. Confirm Composer resolution in a clean environment and in CI. Check whether function mocking requires namespaced test classes or specific bootstrap ordering. Validate license acceptance with legal/procurement if WTFPL is unfamiliar to stakeholders.
Sequencing:
Maintenance: Low operational surface because it is test-only, but maintenance confidence is limited by low adoption, unknown repository ownership, and minimal community validation. The recent release date is positive but insufficient alone. Plan for periodic compatibility checks rather than assuming long-term support.
Support: Community support is likely thin. There is no obvious vendor backing. Internal owners should be prepared to fork, patch, or replace the package if it breaks. Avoid making it a critical dependency for large or regulated test suites without an exit plan.
Scaling: Scaling concerns apply to test-suite size and CI, not production traffic. Function mocking can make tests more coupled to global state, complicate parallel execution, and slow diagnosis. Keep usage scoped; do not let it become the default way to handle time, randomness, or I/O in tests.
Failure modes: Common risks include mocked functions leaking between tests, namespace/autoload mismatches, incompatibility with PHP or Prophecy upgrades, Composer dependency conflicts, CI-only failures, and abandoned-package risk. Because the package targets built-in functions, failures can be subtle and test-order-dependent.
Ramp-up: Low initial ramp-up for engineers familiar with Prophecy and php-mock concepts; moderate for a Laravel team standardized on PHPUnit/Pest and Mockery. The main learning is not the API but the guardrails: when to mock built-ins, how to isolate mocks, and when to refactor instead. Recommend a short internal pattern note and a single owner for test infrastructure.
TPM recommendation: Approve only as a time-boxed, test-only pilot for legacy Prophecy-based tests. Do not treat it as a strategic dependency. If the pilot shows CI instability, unclear provenance, or easy refactoring alternatives, reject or replace it with an internal helper or dependency injection.
How can I help you explore Laravel packages today?