Download the PHP package php-mock/php-mock-phpunit without Composer
On this page you can find all versions of the php package php-mock/php-mock-phpunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-mock/php-mock-phpunit
More information about php-mock/php-mock-phpunit
Files in php-mock/php-mock-phpunit
Package php-mock-phpunit
Short Description Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.
License WTFPL
Homepage https://github.com/php-mock/php-mock-phpunit
Informations about the package php-mock-phpunit
Mock PHP built-in functions with PHPUnit
This package integrates the function mock library PHP-Mock with PHPUnit.
Installation
Use Composer:
Usage
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 namespacefoo
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 [email protected].
Donations
If you like this project and feel generous donate a few Bitcoins here: 1335STSwu9hST4vcMRppEPgENMHD2r1REK
All versions of php-mock-phpunit with dependencies
phpunit/phpunit Version ^6 || ^7 || ^8 || ^9 || ^10.0.17 || ^11
php-mock/php-mock-integration Version ^2.3