{"action":"created","issue":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2739","repository_url":"https://api.github.com/repos/sebastianbergmann/phpunit","labels_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2739/labels{/name}","comments_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2739/comments","events_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2739/events","html_url":"https://github.com/sebastianbergmann/phpunit/issues/2739","id":243148765,"node_id":"MDU6SXNzdWUyNDMxNDg3NjU=","number":2739,"title":"Serialization of 'Closure' is not allowed exception when run tests in process isolation mode","user":{"login":"vinterskogen","id":8015372,"node_id":"MDQ6VXNlcjgwMTUzNzI=","avatar_url":"https://avatars0.githubusercontent.com/u/8015372?v=4","gravatar_id":"","url":"https://api.github.com/users/vinterskogen","html_url":"https://github.com/vinterskogen","followers_url":"https://api.github.com/users/vinterskogen/followers","following_url":"https://api.github.com/users/vinterskogen/following{/other_user}","gists_url":"https://api.github.com/users/vinterskogen/gists{/gist_id}","starred_url":"https://api.github.com/users/vinterskogen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinterskogen/subscriptions","organizations_url":"https://api.github.com/users/vinterskogen/orgs","repos_url":"https://api.github.com/users/vinterskogen/repos","events_url":"https://api.github.com/users/vinterskogen/events{/privacy}","received_events_url":"https://api.github.com/users/vinterskogen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-07-15T02:59:05Z","updated_at":"2018-08-27T12:03:45Z","closed_at":"2017-10-13T09:21:21Z","author_association":"NONE","body":"| Q                   | A\r\n| --------------------| ---------------\r\n| PHPUnit version     | 5.7.21\r\n| PHP version         | 7.0.20\r\n| Installation Method | Composer \r\n\r\nI discovered, that phpunit crashes with closure serialisation exception when run a test, that uses a data provider, which returns an object of \\Closure class, as one of elements in a dataset. \r\n\r\n```\r\nPHP Fatal error:  Uncaught Exception: Serialization of 'Closure' is not allowed in /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestCase.php:814\r\n```\r\n\r\nThe following test is green when running in process isolation mode turned off, but causes crash in process isolation mode turned on.\r\n\r\nCode to reproduce error: \r\n\r\n```\r\n<?php\r\n\r\nnamespace Tests\\Unit;\r\n\r\nclass FooTest extends \\PHPUnit_Framework_TestCase\r\n{\r\n    /**\r\n     * Test, that uses a data provider.\r\n     *\r\n     * @dataProvider foobarDataProvider\r\n     * @return void\r\n     */\r\n    public function testFoobar($callback, $expected)\r\n    {\r\n        $actual = call_user_func($callback);\r\n        $this->assertEquals($expected, $actual);\r\n    }\r\n\r\n    /**\r\n     * Data provider, which returns an object of \\Closure class, as one of\r\n     * elements in a dataset.\r\n     *\r\n     * @return array\r\n     */\r\n    public function foobarDataProvider()\r\n    {\r\n        return [[\r\n                function () { return 'foo'; },\r\n                'foo',\r\n            ], [\r\n                function () { return 'bar'; },\r\n                'bar',\r\n            ]\r\n        ];\r\n    }\r\n}\r\n```\r\n\r\nOutput:\r\n```\r\nvinter@vinter-pc /tmp/wtfunit $ ./vendor/bin/phpunit tests/Unit/FooTest.php --process-isolation \r\nPHPUnit 5.7.21 by Sebastian Bergmann and contributors.\r\n\r\nPHP Fatal error:  Uncaught Exception: Serialization of 'Closure' is not allowed in /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestCase.php:814\r\nStack trace:\r\n#0 /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestCase.php(814): serialize(Array)\r\n#1 /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))\r\n#2 /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\r\n#3 /tmp/wtfunit/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(517): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\r\n#4 /tmp/wtfunit/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)\r\n#5 /tmp/wtfunit/vendor/phpunit/phpunit/src/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)\r\n#6 /tmp/wtfunit/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()\r\n#7 {main}\r\n  thrown in /tmp/wtfunit/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 814\r\n```\r\n\r\nMay be related to:\r\n\r\n- https://github.com/sebastianbergmann/phpunit/issues/282\r\n- https://github.com/sebastianbergmann/phpunit/issues/223\r\n- https://github.com/sebastianbergmann/phpunit/issues/1515\r\n- (and more...)\r\n\r\nIs this an expected behavior?\r\n\r\nAre objects of a \\Closure class allowed to be used as a dataset element in data providers? By now docs don't cover this details.\r\n\r\nHope this issue will help to fix it! ;)\r\n\r\n--\r\nRegards,\r\nVinter Skogen"},"comment":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/comments/416204504","html_url":"https://github.com/sebastianbergmann/phpunit/issues/2739#issuecomment-416204504","issue_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2739","id":416204504,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjIwNDUwNA==","user":{"login":"dawei101","id":2274609,"node_id":"MDQ6VXNlcjIyNzQ2MDk=","avatar_url":"https://avatars3.githubusercontent.com/u/2274609?v=4","gravatar_id":"","url":"https://api.github.com/users/dawei101","html_url":"https://github.com/dawei101","followers_url":"https://api.github.com/users/dawei101/followers","following_url":"https://api.github.com/users/dawei101/following{/other_user}","gists_url":"https://api.github.com/users/dawei101/gists{/gist_id}","starred_url":"https://api.github.com/users/dawei101/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dawei101/subscriptions","organizations_url":"https://api.github.com/users/dawei101/orgs","repos_url":"https://api.github.com/users/dawei101/repos","events_url":"https://api.github.com/users/dawei101/events{/privacy}","received_events_url":"https://api.github.com/users/dawei101/received_events","type":"User","site_admin":false},"created_at":"2018-08-27T12:03:45Z","updated_at":"2018-08-27T12:03:45Z","author_association":"NONE","body":"Actually, I think phpunit is not a good tools.\r\nI have got same exception in 4.6 version , also 5.* version\r\n\r\nAnd the most bad thing is , It could pass test in my dev machine, and could not run when in another environment.\r\n------------\r\n\r\nDo you think it would be a good idea  to do that:\r\nuse bash or python to execute only one TestCase class in single process\r\n\r\nThere wont be serialization issues then. \r\n"}}
{"actor":{"display_login":"dawei101"}}