Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.
This repository was 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

Description

@ezzatron

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions