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

catchable fatal error in 3.5 #74

Closed
fentie opened this issue Nov 16, 2010 · 16 comments
Closed

catchable fatal error in 3.5 #74

fentie opened this issue Nov 16, 2010 · 16 comments

Comments

@fentie
Copy link

fentie commented Nov 16, 2010

Catchable fatal error: Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception, instance of __PHP_Incomplete_Class given, called in /Applications/MAMP/bin/php5.3/lib/php/PHPUnit/Util/PHP.php on line 222 and defined in /Applications/MAMP/bin/php5.3/lib/php/PHPUnit/Framework/TestResult.php on line 237

Using the command-line test runner

@sebastianbergmann
Copy link
Owner

I will need a small reproducing test case to investigate this further.

@fentie
Copy link
Author

fentie commented Nov 18, 2010

I've made hours worth of changes since then and worked around the problem, but (I believe) it centered around trying to (erroneously) throw an abstract Exception class. I'm continuing to dig through my change logs and if I can roll back to a non-working state and isolate this I'll let you know. Thanks.

@cobexer
Copy link

cobexer commented Jan 11, 2011

here is the recipe:
phpunitTestExc.php:

result: PHPUnit 3.5.3 by Sebastian Bergmann. PHP Catchable fatal error: Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception, instance of __PHP_Incomplete_Class given, called in /usr/share/php5/PEAR/PHPUnit/Util/PHP.php on line 235 and defined in /usr/share/php5/PEAR/PHPUnit/Framework/TestResult.php on line 237 Catchable fatal error: Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception, instance of __PHP_Incomplete_Class given, called in /usr/share/php5/PEAR/PHPUnit/Util/PHP.php on line 235 and defined in /usr/share/php5/PEAR/PHPUnit/Framework/TestResult.php on line 237 feel free to ask if you need more info ;)

@sebastianbergmann
Copy link
Owner

Should be fixed.

@cobexer
Copy link

cobexer commented Jan 27, 2011

sorry for making noise here again, in what version should it be fixed? i just checked against PHPUnit 3.5.10 and it still shows that error:
PHP Catchable fatal error: Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception, instance of __PHP_Incomplete_Class given, called in /usr/share/php5/PEAR/PHPUnit/Util/PHP.php on line 235 and defined in /usr/share/php5/PEAR/PHPUnit/Framework/TestResult.php on line 242

regards cobexer

@sebastianbergmann
Copy link
Owner

It should have been fixed in PHPUnit 3.5.10. Please provide a small yet complete reproducing example so that I can further investigate.

@cobexer
Copy link

cobexer commented Jan 29, 2011

still happens with the example posted above!

@necromant2005
Copy link

Still reproducing phpunit 3.5.13 / centos 5

@necromant2005 necromant2005 reopened this Apr 28, 2011
@serebrov
Copy link

I also reproduced this: phpunit 3.5.13, ubuntu 10.04.
Note this issue is only reproduced with "--process-isolation" option.
You can see a test case here - https://github.com/sebgoo/testPHPUnit/tree/master/incompleteClassException

@whatthejeff
Copy link
Contributor

This is actually expected behavior if you understand how process isolation works. During process isolation you have one main PHPUnit process that is collecting tests and then a separate PHPUnit process for each test that the main process collects. When one of the separate test processes finishes, it serializes the results and sends them back to the main process.

The problem with your code is that the separate test process is including a file which defines a new exception class that the main process knows nothing about. So when your test throws this new exception, it gets serialized as part of the result object and sent back to the main process. When the main process tries to unserialize the result object, PHP gives a __PHP_Incomplete_Class object for all classes which are not yet defined in the main process (your new exception object). The unfortunate side effect of this is that __PHP_Incomplete_Class fails a type check which causes the error you are reporting.

The remedy for this is pretty simple: be cognizant of how process isolation works and make sure that you are not hiding classes from the main process. The simplest way to do this is to move your file include outside of the class definition. A better way is to use an autoloader.

@cobexer
Copy link

cobexer commented May 20, 2011

My main concern with this is that a test that fails and unexpectedly throws an unknown exception crashes the PHPUnit main process!
why not fix it this way:
the child process knows how to handle that exception. extract all the information the parent process needs in the child process and avoid any such problem.

fixing this in my code is easy, but if it fails it destroys the complete test run. and fixing such a problem in a third party library may not be easy / wanted.

@whatthejeff
Copy link
Contributor

I think it's definitely possible for PHPUnit to handle this more gracefully (and @sebastianbergmann may have some desire to do so), but ultimately the problem is that you're structuring your test in a way that is not compatible with process isolation. If you structure your tests properly, you won't ever encounter this and it won't matter how PHPUnit handles it.

@cobexer
Copy link

cobexer commented May 20, 2011

Hmm i do something and as a result PHPUnit crashes, oh of course i must be
holding it wrong... do you work for apple? /rant

I still think it's a bug and should be fixed.
Am 20.05.2011 08:10 schrieb "whatthejeff" <
reply@reply.github.com>:

I think it's definitely possible for PHPUnit to handle this more
gracefully (and @sebastianbergmann may have some desire to do so), but
ultimately the problem is that you're structuring your test in a way that is
not compatible with process isolation. If you structure your tests properly,
you won't ever encounter this and it won't matter how PHPUnit handles it.

Reply to this email directly or view it on GitHub:
#74 (comment)

@whatthejeff
Copy link
Contributor

I've acknowledged that PHPUnit could handle this situation more gracefully–I was actually planning on looking into this later tonight. I just wanted to help you understand what's going on and how to avoid this situation as it can take a while before patches make it into an official release of PHPUnit and there's no guarantee that Sebastian will accept a patch for this.

@cobexer
Copy link

cobexer commented May 20, 2011

That would be great!
Since i do use code coverage and have code running directly on inclusion of
the class in question. I'm sadly depending on process isolation, it makes
tests run slower too, but this bug was the most annoying part of it.
Many thanks!

@laoneo
Copy link

laoneo commented Jul 19, 2011

What is the status of this issue? Is it fixed or left as it is? If fixed in which release will it be shipped?

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

7 participants