Skip to content

Function spies #145

@paulshryock

Description

@paulshryock

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

Given this function:

myFunction() {
  myOtherFunction();
}

Instead of this 'mock' expectation:

use Brain\Monkey\Functions;

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

I would like to write this 'spy' expectation:

use Brain\Monkey\Functions;

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

Example from Jest: https://jestjs.io/docs/mock-function-api

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions