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

Exception "Serialization of 'Closure' is not allowed" when using assertEquals with processIsolation #1515

Closed
czenker opened this issue Nov 26, 2014 · 5 comments

Comments

@czenker
Copy link

czenker commented Nov 26, 2014

This is a followup to #1351.

When using processIsolation in case of an error an exception is thrown and serialized. The trace might contain arguments that are (or contain) closures which can not be serialized and fail with a message like this

PHPUnit_Framework_Exception: PHP Fatal error:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in -:372
Stack trace:
#0 -(372): serialize(Array)
#1 -(439): __phpunit_run_isolated_test()
#2 {main}
  thrown in - on line 372

The issue has already been addressed (and fixed as far as I can tell) in #1351. This ticket also contains more details. But when using assertEquals this behavior still occurs, because a SebastianBergmann\Comparator\ComparisonFailure is thrown in this case which does not inherit from PHPUnit_Framework_Exception.

Related issues

Temporary workaround

Using assertSame instead of assertEqauls does not show the mentioned behavior.

Proposed fix

The PHPUnit_Framework_Exception might be extracted to a shared library so it could be used in sebastianbergmann/comperator and sebastianbergmann/phpunit alike.

@romanga
Copy link

romanga commented Jan 23, 2015

Hi,
I've ran into same issue, and from reading this post I've tried to make ComparisonFailure to inherit from PHPUnit_Framework_Exception, as last still inherits from RuntimeException and it worked.
Wouldn't that be easier solution as opposed to proposed fix?

@czenker
Copy link
Author

czenker commented Jan 23, 2015

Wouldn't that be easier solution as opposed to proposed fix?

Yes it would. But you would also create a dependency from the comperator package to the full phpunit package which seems a little overkill.

@romanga
Copy link

romanga commented Jan 26, 2015

yeha, just realized that those are separate projects. thanks

@deshack
Copy link

deshack commented Sep 28, 2015

I have a very similar issue when running unit tests in my WordPress Plugin (thus using WP_UnitTestCase, which extends PHPUnit_Framework_Testcase.

Note that I MUST run the tests in process isolation, otherwise they won't work.

Replacing calls to assertEquals() with assertSame() didn't help.

The stack trace is the following:

PHP Fatal error:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in phar:///usr/local/bin/phpunit/phar/phpunit/Util/GlobalState.php:170
Stack trace:
#0 phar:///usr/local/bin/phpunit/phar/phpunit/Util/GlobalState.php(170): serialize(Array)
#1 phar:///usr/local/bin/phpunit/phar/phpunit/Util/GlobalState.php(142): PHPUnit_Util_GlobalState::exportVariable(Array)
#2 phar:///usr/local/bin/phpunit/phar/phpunit/Framework/TestCase.php(622): PHPUnit_Util_GlobalState::getGlobalsAsString()
#3 phar:///usr/local/bin/phpunit/phar/phpunit/Framework/TestSuite.php(735): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#4 phar:///usr/local/bin/phpunit/phar/phpunit/Framework/TestSuite.php(735): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#5 phar:///usr/local/bin/phpunit/phar/phpunit/TextUI/TestRunner.php(432): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 phar:///usr/local/bin/phpunit/phar/phpunit/TextUI/Command.php(148): PHPUnit_Te in phar:///usr/local/bin/phpunit/phar/phpunit/Util/GlobalState.php on line 170

@sebastianbergmann
Copy link
Owner

Dear contributor,

let me start by apologizing for not commenting and/or working on the issue you have reported or merging the pull request you have sent sooner.

PHPUnit 5.0 was released today. And today I am closing all open bug reports and pull requests for PHPUnit and its dependencies that I maintain. Please do not interpret the closing of this ticket as an insult or a lack of interest in your problem. I am sorry for any inconvenience this may cause.

If the topic of this ticket is still relevant then please open a new ticket or send a new pull request. If your ticket or pull request is about a defect then please check whether the issue still exists in PHPUnit 4.8 (which will received bug fixes until August 2016). If your ticket or pull request is about a new feature then please port your patch PHPUnit 5.0 before sending a new pull request.

I hope that today's extreme backlog grooming will allow me to respond to bug reports and pull requests in a more timely manner in the future.

Thank you for your understanding,
Sebastian

Repository owner locked and limited conversation to collaborators Oct 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants