catchable fatal error in 3.5 #74

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

Comments

7 participants
@fentie

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

This comment has been minimized.

Show comment Hide comment
@sebastianbergmann

sebastianbergmann Nov 18, 2010

Owner

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

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

@fentie

This comment has been minimized.

Show comment Hide comment
@fentie

fentie 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.

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

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer 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 ;)

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

This comment has been minimized.

Show comment Hide comment
@sebastianbergmann

sebastianbergmann Jan 15, 2011

Owner

Should be fixed.

Should be fixed.

@cobexer

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer 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

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

This comment has been minimized.

Show comment Hide comment
@sebastianbergmann

sebastianbergmann Jan 27, 2011

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.

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

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer Jan 29, 2011

still happens with the example posted above!

cobexer commented Jan 29, 2011

still happens with the example posted above!

@necromant2005

This comment has been minimized.

Show comment Hide comment
@necromant2005

necromant2005 Apr 28, 2011

Still reproducing phpunit 3.5.13 / centos 5

Still reproducing phpunit 3.5.13 / centos 5

@necromant2005 necromant2005 reopened this Apr 28, 2011

@serebrov

This comment has been minimized.

Show comment Hide comment
@serebrov

serebrov May 10, 2011

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

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

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff May 20, 2011

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.

Contributor

whatthejeff commented May 20, 2011

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

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer 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.

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

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff May 20, 2011

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.

Contributor

whatthejeff commented May 20, 2011

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

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer 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)

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

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff May 20, 2011

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.

Contributor

whatthejeff commented May 20, 2011

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

This comment has been minimized.

Show comment Hide comment
@cobexer

cobexer 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!

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

This comment has been minimized.

Show comment Hide comment
@laoneo

laoneo 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?

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