Skip to content


Subversion checkout URL

You can clone with
Download ZIP


No warning when class to be mocked doesn't exist #728

martinburchell opened this Issue · 1 comment

2 participants


I've been investigating an error when running my tests (PHPUnit 3.6):
PHP Fatal error: Cannot redeclare class Foo

I finally tracked this down to me having created a mock object of class Foo in one test and in a later test using the real class Foo. When the mock object was created, the class Foo didn't exist so PHPUnit silently created it. I was surprised that PHPUnit didn't warn me about this. I guess there must be a case where this is desirable. Is this a bug or something that needs documenting?


Hi, thanks for the bug report.

This is a long standing issue with the Mocking API. It was always able to create new classes and since people depend on it we have to keep it that way for BC reasons.

Implementing a getMockOfExistingClassOrInterface would be easy but the naming is something we have to figure out.

I'd like to be able to just change how getMock works and add another "createClass" or whatever but well.. bc :(

For the same reason adding a warning wouldn't really work out as we would "break" peoples suites by annoying them with warnings.

The tracking issue for this is sebastianbergmann/phpunit-mock-objects#12

@edorian edorian closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.