Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Review how mocked types and ad hoc mock definitions are supplied to mocking functions #117

Closed
ezzatron opened this issue Dec 20, 2015 · 0 comments

Comments

@ezzatron
Copy link
Contributor

Currently ad hoc mocks are specified like this:

mock(
    null, // $types
    [
        'methodA' => function () {}
    ]
);

partialMock(
    null, // $types
    null, // $arguments
    [
        'methodA' => function () {}
    ]
);

But since the first argument to mock() (i.e. $types) already accepts a variety of inputs, it could probably accept definition values directly. They could be distinguished from arrays of multiple types by checking whether the $types has sequential keys:

mock(
    [
        'methodA' => function () {}
    ]
);

partialMock(
    [
        'methodA' => function () {}
    ]
);

This would probably make both mock() and, particularly, partialMock() more intuitive.

The other factors in this equation are mocking of anonymous classes and generic objects, and "mocks that forward to a real instance" (#39).

I recently implemented support for anonymous classes in a branch. It involved accepting an instance of an anonymous class as a type, and doing the following:

  • Implicitly mocking each type extended by, or implemented by, the anonymous class.
  • Adding custom methods for each of the anonymous class' public methods, whose callback simply points back to the anonymous class instance's original public method.

Afterwards, I realised that this almost does what #39 is trying to achieve. Perhaps there's a solution that will cover all these problems, whilst making the interface clearer.

@ezzatron ezzatron added this to the Next release milestone Jan 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant