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.

Nullable parameters with type-hints are not directly supported #114

Description

@jmalloc

The method below has a parameter with that is nullable, followed by a non-optional parameter. It's an unfortunate consequence of using the default value of null to indicate a nullable parameter (rather than something like this that this is perfectly valid and sometimes necessary code.

class Class_
{
    public function method(SomeClass $nullable = null, $notOptional) {}
}

$m = \Eloquent\Phony\Phony::mock(Class_::class);
$m->mock()->method(null, '<any>');

This code fails like so:

Uncaught TypeError: Argument 1 passed to PhonyMock__0::method() must be an
instance of SomeClass, null given, called in test.php on line 17 and defined in
MockFactory.php(146) : eval()'d code:5

I suspect the mock generation code is using the "number of required parameters" from the function reflector to determine whether or not a parameter has a default value, rather than checking each parameter individually, possibly as an optimisation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions