iamfaiz's avatar
Level 10

How to test if a helper function was called inside a class method?

Say I am testing the following class in PHPUnit:

class ExampleClass
{
    public function exampleMethod()
    {
        example_helper_function('firstArg', 'secondArg');
    }
}

How can I test if example_helper_function was called with the arguments 'firstArg' and 'secondArg' when exampleMethod was run?

In other words, how can I mock functions that are not class methods?

0 likes
2 replies
Cronix's avatar

Why not have the function return something that can be checked? You could use that in your tests, and ignore it for regular use if the returned value is not needed.

Please or to participate in this conversation.