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

Cannot expect exception of type "ClassMirrorException" #4123

Closed
Pherserk opened this issue Feb 23, 2020 · 6 comments
Closed

Cannot expect exception of type "ClassMirrorException" #4123

Pherserk opened this issue Feb 23, 2020 · 6 comments
Labels
type/bug Something is broken

Comments

@Pherserk
Copy link

Pherserk commented Feb 23, 2020

Q A
PHPUnit version 9.0
PHP version 7.4.1
Installation Method Composer

Summary

Cannot expect exception of type "ClassMirrorException" when mocking a final class with Prophecy

Current behavior

Given that a ClassMirrorException is thrown during test execution.
If the exception is expected test fails because the exception is never thrown.

How to reproduce

Prophetize a final class with prophecy and expect the exception:

class FinalClassMockingExampleTest extends TestCase
{
public function testNotAllowedFinalClassCannotBeMocked()
{
static::expectException(ClassMirrorException::class);

    static::prophesize(NotAllowedSimpleFinalClass::class);
}

}

Expected behavior

The test does not fails.

@Pherserk Pherserk added the type/bug Something is broken label Feb 23, 2020
@Pherserk Pherserk changed the title Cannot expectException of type "ClassMirrorException" Cannot expect exception of type "ClassMirrorException" Feb 23, 2020
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. A test case that involves Prophecy is not minimal, sorry.

@Pherserk
Copy link
Author

Thank you @sebastianbergmann for the very quick answer.
I have prepared a full self contained and isolated environemnt to reproduce the problem here:
https://github.com/Pherserk/final-class-mocking-examples

If something more is needed let me know.

@sebastianbergmann
Copy link
Owner

I have to repeat myself: a test case that involves Prophecy is not minimal, sorry.

@Pherserk
Copy link
Author

Pherserk commented Feb 23, 2020

Got it.
Sorry I'm not so pratical with this workflow, I have just opened a PR with a regression test.
Hoping it could help.

PR: #4124

And thanks again for the time.

@sebastianbergmann
Copy link
Owner

#4124 still uses Prophecy. Please reproduce the issue you want to report without Prophecy.

@Pherserk
Copy link
Author

Pherserk commented Feb 23, 2020

Of course @sebastianbergmann .
I have tried to replicate the scenario, it seems just an exception using the ReflectionClass and extending a interface nothing more.
This points me to think that is something that stands in the integration seams between phpunit and Prophecy, but of course I cannot be sure, in the next weeks I will find time to run the debugger in my local environment to follow the exception raise path.
Really sorry I cannot contribute immediatly, I need to study the internals first.
Thanks again for all of your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants