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

Not able to make it work (PHP 11 + Mockery) #58

Open bianchi opened 2 weeks ago

bianchi commented 2 weeks ago

I could not make the tool work. I may be doing something wrong.

I'm using phpunit 11 and mockery.

I tried adding the extension to phpunit.xml

<extensions>
    <bootstrap class="DG\BypassFinals\PHPUnitExtension"/>
</extensions>

And tried to use enable on setUp:

protected function setUp(): void
{
    parent::setUp();

    BypassFinals::enable();
}

and also tried to use it inside my test:

public function testCountTokens(): int
{
    BypassFinals::enable();

 .....
}

I got the same error regardless of the alternative: Mockery\Exception: The class \Gemini is marked final and its methods cannot be replaced. Classes marked final can be passed in to \Mockery::mock() as instantiated objects to create a partial mock, but only if the mock is not subject to type hinting checks.