You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP-Mock integrates with the trait
PHPMock
into your PHPUnit test case. This trait extends the framework
by the method
getFunctionMock().
With this method you can build a mock in the way you are used to build a
PHPUnit mock:
There's no need to disable the mocked function. The PHPUnit integration does
that for you.
Restrictions
This library comes with the same restrictions as the underlying
php-mock:
Only unqualified function calls in a namespace context can be mocked.
E.g. a call for time() in the namespace foo is mockable,
a call for \time() is not.
The mock has to be defined before the first call to the unqualified function
in the tested class. This is documented in Bug #68541.
In most cases you can ignore this restriction. But if you happen to run into
this issue you can call PHPMock::defineFunctionMock()
before that first call (e.g. with @beforeClass).
This would define a side effectless namespaced function. Another effective
approach is running your test in an isolated process (e.g. with @runInSeparateProcess).
License and authors
This project is free and under the WTFPL.
Responsable for this project is Markus Malkusch markus@malkusch.de.
Donations
If you like this project and feel generous donate a few Bitcoins here:
1335STSwu9hST4vcMRppEPgENMHD2r1REK
About
Mock built-in PHP functions (e.g. time() or rand()) in PHPUnit.