代码中的 Phpunit 测试给出异常:不允许“Closure”序列化 - Laravel

Tim*_*Uum 3 php laravel laravel-5.1

我的路线中有此代码(只是为了让它工作)。

Route::get('/', function () {
$phpunit = new PHPUnit_TextUI_TestRunner;
try {
    $test_results = $phpunit->dorun($phpunit->getTest('/var/www/cms/tests/', '', 'Test.php'));
    dd($test_results);
} catch (PHPUnit_Framework_Exception $e) {
    print $e->getMessage() . "\n";
    die ("Unit tests failed.");
}
});
Run Code Online (Sandbox Code Playgroud)

从代码运行测试的代码示例可以在此处找到: 可以从脚本运行 PHPUnit 测试吗?

但是当我运行这个时,我收到错误:异常:不允许“闭包”序列化

我无法弄清楚是什么导致了这个错误。

Con*_*olt 5

请参阅https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.backupGlobals

You can turn off this, in config, example:

    <?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="application/tests/bootstrap.php" backupGlobals="false">
    <testsuites>
        <testsuite name="TestSuite">
            <directory>application/tests</directory>
        </testsuite>
    </testsuites>
</phpunit>
Run Code Online (Sandbox Code Playgroud)