badge-poser icon indicating copy to clipboard operation
badge-poser copied to clipboard

Use a standard for mocking dependencies

Open DonCallisto opened this issue 4 years ago • 6 comments

As per https://github.com/PUGX/badge-poser/pull/393#issuecomment-706952070

I would suggest to stick, for the moment, with PHPUnit built in library. Two main reasons

  1. It is still the most used, so we won't prevent any collaboration from contributors that doesn't know about Prophecy
  2. The trait provided for Prophecy usage into PHPUnit could introduce a regression due to Prophecy version 1.10 (see https://github.com/phpspec/prophecy-phpunit/issues/27)

DonCallisto avatar Oct 12 '20 15:10 DonCallisto

so your proposal would be to remove Prophecy and use phpunit exclusively?

/cc @garak @AlessandroMinoccheri

JellyBellyDev avatar Oct 12 '20 17:10 JellyBellyDev

Removing it is not possible. Just don't use Prophecy for the reasons I've stated before. If you take a look to linked issue, you'll notice that Prophecy won't let tests fail immediatly when an unexpected call is made upon a test double (since 1.10). I think is better to stick with PHPUnit built-in system for the moment in order to avoid mistakes from new comers.

DonCallisto avatar Oct 12 '20 17:10 DonCallisto

It could be a solution to use PHPUnit built-in instead of Prophecy. In my opinion, it's not clear if they will fix the bug immediately. To change from PHPUnit built-in to Prophecy and vice versa isn't a big problem but we have to understand when the bug is solved which is the best implementation for us.

AlessandroMinoccheri avatar Oct 12 '20 19:10 AlessandroMinoccheri

In my opinion, it's not clear if they will fix the bug immediately.

AFAIK that's not a bug in Prophecy but the desired behaviour. As a matter of fact, PHPSpec - wich uses only Prophecy as mocking library - is not affected because I suspect, internally it handles checks on double's method invokation differently.

The issue is in the trait and how PHPUnit handle (or, in this case, don't) these scenarios.

DonCallisto avatar Oct 12 '20 21:10 DonCallisto

ok, so I think that use PHPUnit built-in is the best way at the moment to mock dependencies.

AlessandroMinoccheri avatar Oct 12 '20 21:10 AlessandroMinoccheri

ok guys! Thanks so much for the fruitful discussion! 🚀

JellyBellyDev avatar Oct 13 '20 07:10 JellyBellyDev