ErrorException: unserialize(): Error at offset 0 in AbstractPhpProcess.php
| Q | A |
|---|---|
| PHPUnit version | 7.1 |
| PHP version | 7.2 |
| Installation Method | Composer |
from vendor packages installed with composer.
PHPUnit\Framework\Exception: Doctrine\Common\Collections\ArrayCollection {#480
-elements: []
}
Caused by
ErrorException: unserialize(): Error at offset 0 of 68 bytes in /var/www/site/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:247
Stack trace:
#0 [internal function]: PHPUnit\Util\PHP\AbstractPhpProcess->PHPUnit\Util\PHP\{closure}(8, 'unserialize(): ...', '/var/www/site...', 247, Array)
#1 /var/www/site/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php(247): unserialize('Doctrine\\Common...')
for
public function AuthenticationForm_WithValidCredentials_Submit(string $url) : void
{
$client = static::createClient([], ['HTTPS' => true]);
$crawler = $client->request('GET', $url);
$form = $crawler->filter('form')->form();
$credentials = ['email' => '[email protected]', 'password' => 'admin'];
$client->submit($form, $credentials);
$client->followRedirect();
$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());
}
It was working on PhPUnit 6 i think, so before upgrade
Configs
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="./vendor/autoload.php"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutTodoAnnotatedTests="true"
stopOnError="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
processIsolation="true"
stopOnFailure="false">
Without processIsolation we got
Doctrine\Common\Collections\ArrayCollection {#5735
-elements: []
}
And that is it, result of test
I am not sure is it doctrine, some settings, symfony or PhPUnit, i missed time when some changes were made and broke it. Other tests are passed well.
Thanks for help.
Thank you for your report.
Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.
Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.
That was from our side. Issue can be closed. Thank you.
Hi guys. I have the same problem.
@BonBonSlick What's the modification you've done to do it works ?
Thanks !
Hello, the same thing is happening to me. Soon I share more information.
See: https://github.com/sebastianbergmann/phpunit/issues/3165
@BonBonSlick how did you fix it? Please share your knowledge.
OK finally we found the problem. While the error message
ErrorException: unserialize(): Error at offset... seemed to point a problem in PHPUnit code. The problem over here was that the assertion we used was wrong / failed. The test itself did run but the assertion failed. So in our case our test first looked like this (Laravel 4.2):
/**
* A basic functional test example.
* @runInSeparateProcess
*/
public function test302Redirect()
{
//enable filters
\Route::enableFilters();
$this->call(
'GET',
'http://my-application/highscores'
);
$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
}
But status code we recived was 301 - so we fixed this:
/**
* A basic functional test example.
* @runInSeparateProcess
*/
public function test301Redirect()
{
//enable filters
\Route::enableFilters();
$this->call(
'GET',
'http://my-application/highscores'
);
$this->assertEquals(301, $this->client->getResponse()->getStatusCode());
}
Finally the error message went away. Unfortunately, when running @runInSeparateProcess PHPUnit seems not recognizing the correct error message thrown by the assertion we used. Instead this ends up in a PHP error.
I hope this will help others. Take a look at your tests and ensure the assertions are valid.
Helpful links:
- https://stackoverflow.com/questions/14492486/unserialize-error-when-runinseparateprocess?lq=1
@linslin problems mostly because of your code. It is not related to phpunit. You are doing something wrong, i do not remmber already how solved it, but it was not phpunit issue.
That was from our side. I
I just stumbled upon this thread searching for "phpunit errorexception unserialize error at offset 0" as one of the few results.
For me the solution was to disable XDebug since it polluted the output of php when phpunit was running its tests.
Same thing seems to be the case with the original author's problem where you can see in the stack trace that it begins with unserialize('Doctrine\\Common...') which is definitely not valid serialized data.
I was scratching my head over this ticket and comment chain since it sounded unlikely that phpunit would just fail this hard on an unexpected return value because it should just mark the test as failed in this case.
The actual issue seems to be either polluted php output or uncaught exceptions in the code which is being tested.
Any dd(), dump(), var_dump(), print_r() of these functions called in your test case will throw that error exception now... is this intentional?
in my case, this is what I have in that test case, note its not even the first test case in that there are several others before that works but this one
/**
* @test
*/
public function it_responds_with_200_if_there_are_no_associationss() {
dd('mhgvjhgvkh');
}
And I still get that error. Really dont know what to do. The tests is existing test I cannot remove it. (I intentionally removed the actual content of the test and reduced to just a dd)
in my case, this is what I have in that test case, note its not even the first test case in that there are several others before that works but this one
/** * @test */ public function it_responds_with_200_if_there_are_no_associationss() { dd('mhgvjhgvkh'); }And I still get that error. Really dont know what to do. The tests is existing test I cannot remove it. (I intentionally removed the actual content of the test and reduced to just a dd)
Holy cow!!!! There happens to be a missing migration digging further. It was a painful digging tho. So instead of just erroring out as usual I'm met with that error that tells me nothing but cause PTSD. Glad I was able to figure this out. So like something said earlier, its likely something in the code it may just be too hard or painful to find.