dg / bypass-finals

Removes `final` and `readonly` keywords from source code on-the-fly and allows mocking of final methods and classes. It can be used together with any test tool such as PHPUnit or Mockery.
Other
487 stars 30 forks source link

Bypassing finals does not work with PHPUnit's --order-by set to random #36

Closed Ilyes512 closed 2 years ago

Ilyes512 commented 2 years ago

It seems that this library does not work when you use PHPUnit together with the --order-by random flag.

I have only confirmed this on one project (maybe someone else can confirm this by running $ phpunit --order-by random in a project using this library?

I am using PHP 8.1.6 with PHPUnit 9.5.24.

Ilyes512 commented 2 years ago

Hmm I think I found the cause...

I have 2 separate testsuites (Unit and Feature). I was only using BypassFinals::enable() in some of the Unit testcases where I was mocking some of the classes.

The problem is that the class was probably already loaded by a Feature test where I was not calling BypassFinals::enable(). Once I added also called BypassFinals::enable() in all feature tests it was working as it should.

So I guess it works! All is good! Closing this. Thanks!