phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

Mocking symfony's `ValidatorInterface` results in "wrong" mock instance #513

Closed cjost1988 closed 2 years ago

cjost1988 commented 3 years ago

Hi,

I am trying to mock ValidatorInterface https://github.com/symfony/validator/blob/5.x/Validator/ValidatorInterface.php and inject it into a service that is depending on a class instance implementing this interface.

Following error occurs and I don't really understand it:

__construct() must be an instance of Symfony\Component\Validator\Validator\ValidatorInterface, instance of Double\stdClass\P1 given, called in

I tried to find some information on the internet but that wasn't successful.

Thanks in advance.

Cheers, Chris

stof commented 3 years ago

Can you share a reproducer ?

ciaranmcnulty commented 3 years ago

The error indicates that prophecy didn’t know what class to double

cjost1988 commented 3 years ago

Thanks for your responses. Sadly this issue does not occur with a brand new installation of symfony 3/4/5 - I've tested them all. I will now try to identify why this is happening in existing projects. I guess it's related to a dedicated component installed.

ciaranmcnulty commented 3 years ago

@ptdias25 any chance you could share some code that reproduces it?

ptdias25 commented 3 years ago

@ptdias25 any chance you could share some code that reproduces it?

the error was on my side, sorry :X thanks for the quick reply!