2

Today my tests are all giving me Serialization of 'Closure' is not allowed errors. A few days ago they were working fine. This seems odd as I haven't made any real code changes and these methods mostly haven't got any closures in them. Even an empty test method causes the error.

namespace MyCode\Tests;

Class Setup extends \PHPUnit_Framework_TestCase {
    public function testSomething(){}
}

The error:

PHPUnit 5.2.10 by Sebastian Bergmann and contributors.

E                                                               1 / 1 (100%)

Time: 119 ms, Memory: 3.00Mb

There was 1 error:

1) MyCode\Tests\Setup::testSomething
Exception: Serialization of 'Closure' is not allowed

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
[Finished in 0.1s]

So if this error is not coming from this test, where else could it be coming from?

To the best of my knowledge I haven't updated any software recently. I am using PHP7 but as I said this was working fine the other day which was definitely on PHP7.

NikiC
  • 100,734
  • 37
  • 191
  • 225
Coin_op
  • 10,568
  • 4
  • 35
  • 46
  • 1
    guessing - maybe interesting [Symfony 2 + Doctrine 2 + PHPUnit 3.5: Serialization of closure exception](http://stackoverflow.com/questions/4366592/symfony-2-doctrine-2-phpunit-3-5-serialization-of-closure-exception/5133558#5133558). – Ryan Vincent Mar 14 '16 at 00:32
  • 7
    Thanks for the pointer, found my issue. An include in my bootstrap file had been altered so a global was being created which had an anonymous function assigned to it. Adding the backupGlobals="false" attribute to the phpunit tag in my xml appears to have fixed the issue for now. – Coin_op Mar 14 '16 at 00:44

0 Answers0