[wp-trac] [WordPress Trac] #50482: Uncaught Exception: Serialization of 'Closure' is not allowed when run PHPUnit in plugin development

WordPress Trac noreply at wordpress.org
Sat Aug 7 15:52:19 UTC 2021


#50482: Uncaught Exception: Serialization of 'Closure' is not allowed when run
PHPUnit in plugin development
------------------------------+------------------------------
 Reporter:  yshinoda          |       Owner:  (none)
     Type:  defect (bug)      |      Status:  reopened
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Build/Test Tools  |     Version:  5.5
 Severity:  critical          |  Resolution:
 Keywords:  close             |     Focuses:
------------------------------+------------------------------
Changes (by jrf):

 * keywords:   => close


Comment:

 In my experience, these type of errors are typical on older PHPUnit
 versions being run on incompatible, more recent PHP versions, when the
 `@runInSeparateProcess` annotation is used and there is an error somewhere
 in the code being run via the test.

 In this case, using PHPUnit 5.x on PHP 7.3 is the first thing to fix. Use
 PHPUnit 7.x instead when running tests on PHP 7.3.

 I concur with @thomasplevy that using `@preserveGlobalState disabled` can
 sometimes help.
 @TimothyBlynJacobs suggestion about using `wp_die()` instead of `die()` is
 also very valid.

 Additionally, declaring that particular test class in a separate
 `testsuite` in the PHPUnit configuration can also often be used as a work-
 around.

 As a debugging method, I'd generally recommend isolating the problem test
 to their own file, removing the annotation and then running just and only
 that test, for instance by using `--filter TestClass::testName` on the
 command line.

 That should then show the underlying error and once that it solved, the
 test can be brought back to its normal state.

 Also now the patches for #46149 have been committed, more recent versions
 of PHPUnit can now be used with the Core tests and in my experience, those
 should no longer display this particular error, but should display an
 error for the ``real``, underlying issue.

 So if this is a Core test, please use PHPUnit 9.x when testing on PHP 7.3
 as of now. You should get this automatically when running `composer
 update` on PHP 7.3.

 If the issue is in a (integration) test suite for a plugin/theme, a Make
 post will be published over the next couple of weeks with information on
 how to update your tests to also make them cross-version compatible with a
 wider range of PHPUnit versions.

 As this is not a problem with Core directly, but rather with an
 incompatible test setup, possible combined with a bug in the code under
 test in a plugin/themes, I'd like to suggest closing this issue.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50482#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list