This continues the discussion started by @docteurklein in phpspec/phpspec#230 (comment) as he made a valid argument:
Take the following spec:
function it_does_something_with_a_token(ArrayToken $token)
{
$token->getId()->willReturn(1234);
$this->foo($token)->shouldReturn(1234);
}
function it_does_something_special_with_object_token(ObjectToken $token)
{
$token->getId()->willReturn(null);
$this->foo($token)->shouldReturn(3);
}
In this case, both examples will ask for the generation of foo. But applyignt he current logic will typehint it as ArrayToken or ObjectToken (depending of which example wins) and the other example will explode with a fatal error.
But the spec here allows you to know that none of these typehints are the expected one. In such case, it should look for all cases asking for generation, and find the common type (by looking at the common ancestor class in the inheritance hierarchy or a common interface)
This continues the discussion started by @docteurklein in phpspec/phpspec#230 (comment) as he made a valid argument:
Take the following spec:
In this case, both examples will ask for the generation of
foo. But applyignt he current logic will typehint it asArrayTokenorObjectToken(depending of which example wins) and the other example will explode with a fatal error.But the spec here allows you to know that none of these typehints are the expected one. In such case, it should look for all cases asking for generation, and find the common type (by looking at the common ancestor class in the inheritance hierarchy or a common interface)