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.

Allow ad hoc mock method implementations to specify whether the function signature from an overridden method should be used when generating the mock class #267

@ezzatron

Description

@ezzatron

See #253 for context.

Given some type with a method:

interface SomeType
{
    public function someMethod(string $arg): string|int;
}

A "standard" ad hoc mock like the following one would result in a mock class with someMethod having the signature (string|int): string (matching the signature of the ad hoc implementation):

partialMock([
    SomeType::class,
    [
        'someMethod' => function (string|int $arg): string {
        },
    ]
]);

Whereas a special token like {useOriginalSignature} would change the behaviour and result in a mock class with someMethod having the signature (string): string|int (matching the signature of the original method):

partialMock([
    SomeType::class,
    [
        'someMethod {useOriginalSignature}' => function (string|int $arg): string {
        },
    ]
]);

Alternatively, perhaps the behaviour could be flipped, defaulting to using the overridden method's signature, and a keyword like override (inspired by languages that require explicit override declaration) could indicate that the signature of the ad hoc implementation should be used. This would be a BC break, however.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions