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

unserialize when @runInSeparateProcess triggers an error #1571

Closed
Fuco1 opened this issue Jan 8, 2015 · 7 comments
Closed

unserialize when @runInSeparateProcess triggers an error #1571

Fuco1 opened this issue Jan 8, 2015 · 7 comments

Comments

@Fuco1
Copy link

Fuco1 commented Jan 8, 2015

When I run test in separate process, PHPUnit tries to do some marshalling between the processes. From time to time, I get an unserialize offset error, here's an example:

PHPUnit 4.4.1 by Sebastian Bergmann.

E

Time: 1.06 seconds, Memory: 10.25Mb

There was 1 error:

1) COrderMethodNormalUnitTest::testComputeOrder with data set #0 (58)
PHPUnit_Framework_Exception: 

composer/vendor/phpunit/phpunit/phpunit:62

Caused by
exception 'ErrorException' with message 'unserialize(): Error at offset 0 of 1 bytes' in composer/vendor/phpunit/phpunit/src/Util/PHP.php:144
Stack trace:
#0 [internal function]: {closure}(8, 'unserialize(): ...', '/var/www/html/d...', 144, Array)
#1 composer/vendor/phpunit/phpunit/src/Util/PHP.php(144): unserialize('?')
#2 composer/vendor/phpunit/phpunit/src/Util/PHP.php(88): PHPUnit_Util_PHP->processChildResult(Object(COrderMethodNormalUnitTest), Object(PHPUnit_Framework_TestResult), '?', '')
#3 composer/vendor/phpunit/phpunit/src/Framework/TestCase.php(720): PHPUnit_Util_PHP->runTestJob('<?php?if (!defi...', Object(COrderMethodNorhttps://github.com/sebastianbergmann/phpunit/blob/master/src/Util/PHP.php#L109malUnitTest), Object(PHPUnit_Framework_TestResult))
#4 composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php(751): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#5 composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php(751): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php(751): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#7 composer/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(423): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#8 composer/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#9 composer/vendor/phpunit/phpunit/src/TextUI/Command.php(138): PHPUnit_TextUI_Command->run(Array, true)
#10 composer/vendor/phpunit/phpunit/phpunit(62): PHPUnit_TextUI_Command::main()
#11 {main}
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

After googling around I've found http://www.microtuts.com/php-unserialize-error-at-offset-simple-solution/ and indeed applying this fixed the issue.

Specifically, I've added trim before unseralize here: https://github.com/sebastianbergmann/phpunit/blob/master/src/Util/PHP.php#L109

The test code can be reduced to this and I can still reproduce the error

/**
 * @dataProvider plidProvider
 * @runInSeparateProcess
 */
public function testComputeOrder($plid)
{
    $this->assertEquals(true, true);
}

public function plidProvider() {
    return array(array(58));
}

I'm no PHP wizzard so I have no idea if the trim there can cause any trouble. I'm going to use it in on instance, will report back if I find any troubles with it.

@whatthejeff
Copy link
Contributor

Curious why the output would be a single byte of whitespace. It should contain a serialized array, so there must be some additional problem here.

Unfortunately, I can't seem to reproduce the issue with the information you've provided. Would it be possible for you to provide a complete example (maybe as a github repo)?

@Fuco1
Copy link
Author

Fuco1 commented Jan 12, 2015

I'm trying to use PHPUnit to test quite large application at work, for obvious reasons I can't put it somewhere as a public repo. I'll try to distill it to something usable, but I'm afraid it won't be possible... it's a "legacy" application with structure totally unfit for testing.

What I was trying to write weren't even unit tests in the usual sense, I need to set up lots of environment including databases and network etc., so maybe PHPUnit just isn't the tool for the job.

@staabm
Copy link
Contributor

staabm commented Apr 14, 2015

I am also expericing this problem... investigating...

hmm could the reason be caused by a error which also leads to "headers already sent"-errors, e.g. a whitespace after ?> or before <?php etc...?

or maybe php startup errors or something like that..?

FYI: I am on
Ubuntu 14 LTS
PHP 5.6.7-1+deb.sury.org~trusty+1
phpunit 4.6.4

@enl
Copy link

enl commented Apr 22, 2015

I have exactly the same error, but in a different place:

1) Kidly\Test\Unit\Controller\API\PurchasesTest::shouldThrowBadRequestOnEmptyRequest
PHPUnit_Framework_Exception: []

Caused by
exception 'ErrorException' with message 'unserialize(): Error at offset 0 of 2 bytes' in /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Util/PHP.php:113
Stack trace:
#0 [internal function]: PHPUnit_Util_PHP->{closure}(8, 'unserialize(): ...', '/home/enlighten...', 113, Array)
#1 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Util/PHP.php(113): unserialize('[]')
#2 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Util/PHP.php(56): PHPUnit_Util_PHP->processChildResult(Object(Kidly\Test\Unit\Controller\API\PurchasesTest), Object(PHPUnit_Framework_TestResult), '[]', '')
#3 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Framework/TestCase.php(697): PHPUnit_Util_PHP->runTestJob('<?php\nif (!defi...', Object(Kidly\Test\Unit\Controller\API\PurchasesTest), Object(PHPUnit_Framework_TestResult))
#4 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#5 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(406): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#7 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/TextUI/Command.php(153): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#8 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/src/TextUI/Command.php(105): PHPUnit_TextUI_Command->run(Array, true)
#9 /home/enlightened/projects/kidly/vendor/phpunit/phpunit/phpunit(36): PHPUnit_TextUI_Command::main()
#10 {main}
2) Kidly\Test\Unit\Controller\API\PurchasesTest::shouldThrowNotAuthorizedExceptionIfNoUserIsGiven
PHPUnit_Framework_Exception: []

phpunit 4.6.4
PHP 5.6.1
OpenSUSE 13.2

@tallona
Copy link

tallona commented May 11, 2015

I've come across this error also.

1) Interfaces\Test::testIntitialise
PHPUnit_Framework_Exception: <response>
    <status>SUCCESS</status>
    <status-message>DB Success: data updated</status-message>
    <status-id>1</status-id>
</response>

phar://C:/PHP/phpunit/phpunit/TextUI/Command.php:179
phar://C:/PHP/phpunit/phpunit/TextUI/Command.php:132

Caused by
exception 'ErrorException' with message 'unserialize(): Error at offset 0 of 142 bytes' in C:\code\phpunit\phpunit\src\Util\PHP.php:109
Stack trace:
#0 [internal function]: PHPUnit_Util_PHP->{closure}(8, 'unserialize(): ...', 'C:\\code\\phpunit\\ph...', 109, Array)
#1 C:\code\phpunit\phpunit\src\Util\PHP.php(109): unserialize('<response>\n    ...')
#2 C:\code\phpunit\phpunit\src\Util\PHP.php(53): PHPUnit_Util_PHP->processChildResult(Object(\Interfaces\Test), Object(PHPUnit_Framework_TestResult), '<response>\n    ...', '')
#3 C:\code\phpunit\phpunit\src\Framework\TestCase.php(691): PHPUnit_Util_PHP->runTestJob('<?php\nif (!defi...', Object(\Interfaces\Test), Object(PHPUnit_Framework_TestResult))
#4 C:\code\phpunit\phpunit\src\Framework\TestSuite.php(716): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#5 C:\code\phpunit\phpunit\src\Framework\TestSuite.php(716): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 C:\code\phpunit\phpunit\src\TextUI\TestRunner.php(398): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#7 phar://C:/PHP/phpunit/phpunit/TextUI/Command.php(179): PHPUnit_TextUI_TestRunner->doRun(Object(NetBeansSuite), Array)
#8 phar://C:/PHP/phpunit/phpunit/TextUI/Command.php(132): PHPUnit_TextUI_Command->run(Array, true)
#9 C:\PHP\phpunit(583): PHPUnit_TextUI_Command::main()
#10 {main}

PHPUnit 4.0.17
PHP 5.6.7
Windows 8.1

@edhelas
Copy link

edhelas commented Sep 29, 2015

Same issue here

PHPUnit_Framework_Exception: ...

phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:179
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:132

Caused by
exception 'ErrorException' with message 'unserialize(): Error at offset 0 of 81 bytes' in /vendor/phpunit /phpunit/src/Util/PHP.php:107

@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

7 participants