qubit05 / phpunit-mockfunction
PHPUnit extension to Mock PHP internal functions using Runkit.
1.0.1
2013-04-22 13:20 UTC
Requires
- ext-runkit: *
This package is not auto-updated.
Last update: 2024-11-18 11:29:16 UTC
README
PHPUnit extension to Mock PHP internal functions using Runkit.
Requirements
*This is an optional requirement. Runkit doesn't currently support the override of internal functions (exit, die etc).
Installation
Using composer, add the following to the composer.json file:
{
"require": {
"qubit05/phpunit-mockfunction": "1.*"
}
}
Example
ExampleClass.php
<?php
class ExampleClass
{
public function doExample()
{
return date();
}
}
ExampleClassTest.php
<?php
class ExampleClassTest extends \PHPUnit_Framework_TestCase
{
public function testExample()
{
$param = 'Y-m-d H:i:s';
$value = 'non date value';
$mockFunction = new PHPUnit_Extensions_MockFunction('date', $this);
$mockFunction->expects($this->once())
->with($this->equalTo($param))
->will($this->returnValue($value));
$exampleClass = new ExampleClass();
$this->assertEquals($value, $exampleClass->doExample($param));
}
}
Acknowledgement
When this class was created, some inspiration was taken from tcz/phpunit-mockfunction. The two classes are similar but not the same.