phpstan-phpspec icon indicating copy to clipboard operation
phpstan-phpspec copied to clipboard

Make SpoofedCollaborator implement or extend wrapped class

Open akondas opened this issue 7 years ago • 4 comments

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.  

akondas avatar Dec 31 '18 07:12 akondas

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:.

akondas avatar Dec 31 '18 12:12 akondas

Just stated testing this extension, right now I see 2 problems:

  1. what is described just above.

  2. 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.

babaorum avatar Jan 03 '19 19:01 babaorum

The second problem concerns the same, so the same fix will solve both cases.

akondas avatar Jan 03 '19 21:01 akondas

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.

akondas avatar Jan 10 '19 19:01 akondas