PHPUnit: makes fun of a function

Is it possible to create a layout for this function?

UPD1

$class->callback('callback_function');

I tried to check if the call was callback_functiononce or not.

+3
source share
2 answers

Native functions cannot be mocked. You will need something like runkit or patchwork to do this.

What could you do by using a strategy template and transferring your own function calls to separate Command Objects or Closures / Lambdas and using instead. They can be exchanged and freely exchanged.

Example 1 - Using the lambda function:

$callback = function() { 
    // a native function in here
}
$class->callback($callback);

Example 2 - Using the Command Object:

interface ICommand
{ 
    public function execute();
}
class Callback implements ICommand
{
    public function execute()
    { 
        // a native function in here
    }
}
$class->callback(array('Callback', 'execute'));

. , PHPUnit " ". /.

+3

Runkit, , PHPUnit mock framework:

https://github.com/tcz/phpunit-mockfunction

+2

Source: https://habr.com/ru/post/1754067/


All Articles