Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bianchi opened this issue Nov 13, 2024 · 3 comments
Open

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

bianchi opened this issue Nov 13, 2024 · 3 comments

Comments

@bianchi
Copy link

bianchi commented Nov 13, 2024

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.

@kohlerdominik
Copy link

I had the same issue (with PHPUnit10) and for me it seemed like, that not all files were piped through the stream-wrapper.

For me it worked to use https://github.com/nunomaduro/mock-final-classes instead of the PHPUnit-extension.

@zluiten
Copy link

zluiten commented Dec 27, 2024

This can be caused by having dataProviders using classes that are marked final. This is because, with PHPUnit 10, the testSuite is build before the extensions are executed. Part of building the testSuite is that all the data providers are being invoked.

https://github.com/sebastianbergmann/phpunit/blob/10.5/src/TextUI/Application.php#L113..L125

@dg
Copy link
Owner

dg commented Dec 27, 2024

I added a method BypassFinals::debugInfo() to help you with troubleshooting d738898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants