Make SpoofedCollaborator implement or extend wrapped class
This is problem, when collaborator is used not only in Subject or Collaborator, for example:
public function it_should_be_nice_spec(Client $client): void
{
$this->doSomethingMore($client);
$this->make($client)->shouldReturn('magic');
}
private function doSomethingMore(Client $client): void
{
}
34 Parameter #1 $client of method
spec\SomeSpec::doSomethingMore() expects
Client,
class@anonymous\/var/www/proget/vendor/proget-hq/phpstan-phpspec/src/NodeVisitor/Collab
oratorResolver.php(42) : eval()'d code0x7f3a250371b2 given.
This is more complex but should be possible. We must find out (on parse level) is source class is interface or standard class. Of course, if the class is final then :skull:.
Just stated testing this extension, right now I see 2 problems:
-
what is described just above.
-
almost the opposite
function it_do_something()
{
$this->doSomethingMore(new Foo());
}
private function doSomethingMore(Foo $foo)
{
foreach ($foo as $bar) {
// ...
}
}
97 Argument of an invalid type
class@anonymous\/www-data/vendor/proget-hq/phpstan-phpspec/src/NodeVisi
tor/CollaboratorResolver.php(42) : eval()'d code0x7ff73082e752 supplied
for foreach, only iterables are supported.
with a foo class that implement \IteratorAggregate for example.
I am not sure if the second problem is unrelated to the first one. If so I can create a dedicated issue.
The second problem concerns the same, so the same fix will solve both cases.
This is more complicated, because in the case of an interface, you need to add an implementation, but he is in the middle of work, I will inform you.