Skip to content

qubit05/phpunit-mockfunction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHPUnit Mock Function

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.

About

PHPUnit extension to Mock PHP internal functions using Runkit.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages