Registry / testing / php-mock-php-mock

php-mock-php-mock

JSON →
library2.7.0phppackagistunverified

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

composer require php-mock/php-mock
INSTALL
IMPORT
SIG · PHP-MOCK-PHP-MOCK
P
php-mock-php-mock
testingphpv2.7.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 using PHPUnit.

use phpmock\phpunit\PHPMock; class MyTest extends \PHPUnit\Framework\TestCase { use PHPMock; public function testTime() { $timeMock = $this->getFunctionMock('my\namespace', 'time'); $timeMock->expects($this->once())->willReturn(1234567890); $result = \my\namespace\time(); $this->assertEquals(1234567890, $result); } }
Debug
Known issues
gotchaPHP-Mock only works for functions in namespaces that use the fallback to global functions.
fix
Ensure the code under test uses the function without a leading backslash (e.g., time() instead of \time()).
affects: >=2.0.0
Upgrade
Version history
2.7.0latest on Packagist
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
php-mock-php-mock — pip install php-mock-php-mock · libregistry