Registry / testing / php-mock-php-mock-phpunit

php-mock-php-mock-phpunit

JSON →
library2.15.0phppackagistunverified

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

composer require php-mock/php-mock-phpunit
INSTALL
IMPORT
SIG · PHP-MOCK-PHP-MOCK-
P
php-mock-php-mock-phpunit
testingphpv2.15.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PHPMock
use phpmock\phpunit\PHPMock;

Mock the time() function in a specific namespace

use phpmock\phpunit\PHPMock; class MyTest extends \PHPUnit\Framework\TestCase { use PHPMock; public function testTime() { $time = $this->getFunctionMock('MyNamespace', 'time'); $time->expects($this->once())->willReturn(1234567890); // Now time() in MyNamespace returns 1234567890 } }
Debug
Known issues
gotchaOnly mocks functions in the same namespace as the tested code; does not affect global namespace.
fix
Ensure the tested code uses the function without leading backslash
affects: >=1.0.0
Upgrade
Version history
2.15.0latest on Packagist
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
php-mock-php-mock-phpunit — pip install php-mock-php-mock-phpunit · libregistry