Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Php Mock Prophecy

Php Mock Prophecy Laravel Package

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.

Deep Wiki
Context7

php-mock-prophecy integrates php-mock with Prophecy, enabling you to mock PHP’s built-in functions—such as time(), sleep(), or rand()—inside Prophecy-based test suites. It bridges php-mock’s function proxies with Prophecy’s mocking API, so tests can control global function calls without changing production code.

  • Mock built-in PHP functions in Prophecy tests
  • Seamless integration with php-mock function proxies
  • Supports Prophecy expectations and predictions
  • Fits PHPUnit and Prophecy testing workflows
  • Namespaced mocking helps avoid global side effects
Frequently asked questions about Php Mock Prophecy
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console