Brain-WP / BrainMonkey

Mocking utility for PHP functions and WordPress plugin API
https://giuseppe-mazzapica.gitbook.io/brain-monkey/
MIT License
304 stars 29 forks source link

Function spies #145

Open paulshryock opened 3 months ago

paulshryock commented 3 months ago

Is there a way to create a function spy with Brain Monkey?

Given this function:

myFunction() {
  myOtherFunction();
}

Instead of this 'mock' expectation:

it('should call my other function', function() {
  Functions\expect('myOtherFunction')->once();
  myFunction();
});

I would like to write this 'spy' expectation:

it('should have called my other function', function() {
  Functions\spy('myOtherFunction');
  myFunction();
  Functions\expect('myOtherFunction')->shouldHaveBeenCalled()->once();
});