Phpunit: ErrorException: unserialize(): Error at offset 0 in AbstractPhpProcess.php

Created on 23 May 2018  路  7Comments  路  Source: sebastianbergmann/phpunit

| 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.

Most helpful comment

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:

All 7 comments

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:

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TiMESPLiNTER picture TiMESPLiNTER  路  3Comments

kunjalpopat picture kunjalpopat  路  4Comments

joubertredrat picture joubertredrat  路  4Comments

edyan picture edyan  路  4Comments

rentalhost picture rentalhost  路  4Comments