| Q | A
| --------------------| ---------------
| PHPUnit version | 6.1.0
| PHP version | 7.0.8
| Installation Method | PHAR
Trying to test method with output stream in separate process, also as recommended here - https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.preserveGlobalState
set the @preserveGlobalState disabled annotation, but the test fails with error:
There was 1 error:
1) rjapitest\unit\BaseControllerTest::testJsonApiIndex
PHPUnit\Framework\Exception: {"data":[{"type":"article","id":"36","attributes":{"title":"Foo bar Foo bar Foo bar Foo bar 123456789"},"links":{"self":"localhost\/article\/36"}},{"type":"article","id":"37","attributes":{"title":"Foo bar Foo bar Foo bar Foo bar 123456789"},"links":{"self":"localhost\/article\/37"}},{"type":"article","id":"38","attributes":{"title":"Foo bar Foo bar Foo bar Foo bar 123456789"},"links":{"self":"localhost\/article\/38"}}]}
Caused by
ErrorException: unserialize(): Error at offset 0 of 424 bytes in phar:///usr/local/bin/phpunit/phpunit/Util/PHP/AbstractPhpProcess.php:300
Stack trace:
#0 [internal function]: PHPUnit\Util\PHP\AbstractPhpProcess->PHPUnit\Util\PHP\{closure}(8, 'unserialize(): ...', 'phar:///usr/loc...', 300, Array)
#1 phar:///usr/local/bin/phpunit/phpunit/Util/PHP/AbstractPhpProcess.php(300): unserialize('{"data":[{"type...')
#2 phar:///usr/local/bin/phpunit/phpunit/Util/PHP/AbstractPhpProcess.php(205): PHPUnit\Util\PHP\AbstractPhpProcess->processChildResult(Object(rjapitest\unit\BaseControllerTest), Object(PHPUnit\Framework\TestResult), '{"data":[{"type...', '')
#3 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(853): PHPUnit\Util\PHP\AbstractPhpProcess->runTestJob('<?php\nuse Sebas...', Object(rjapitest\unit\BaseControllerTest), Object(PHPUnit\Framework\TestResult))
#4 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(733): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#5 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(733): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#6 phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php(526): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#7 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(209): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#8 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(140): PHPUnit\TextUI\Command->run(Array, true)
#9 /usr/local/bin/phpunit(536): PHPUnit\TextUI\Command::main()
#10 {main}
ERRORS!
Tests: 9, Assertions: 17, Errors: 1.
The executed code snippet:
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testJsonApiIndex()
{
$_SERVER['HTTP_HOST'] = 'localhost';
$request = new \Illuminate\Http\Request();
$request->merge([
'limit' => 10,
'page' => 1,
'data' => '["title", "description"]',
'order_by' => '{"title":"asc", "created_at":"desc"}',
'filter' => '[["updated_at", ">", "2017-01-03 12:13:13"], ["updated_at", "<", "2017-01-03 12:13:15"]]',
]);
$this->articleController->index($request);
}
There are no assertion methods there, but it doesn't matter in this particular case.
Glad to any help.
Any thoughts?
faced same issue yesterday. phpunit 6.1.2
I am having the same issue. Did you manage to find any solution?
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.
No feedback, closing.
This is still broken in 6.5.5, to reproduce uncomment the test at https://github.com/omines/datatables-bundle/blob/1d59c28d43070233c142f479c3894a5dde3da3c3/tests/Unit/Adapter/ElasticaTest.php#L102-L114
I had the same problem. I fixed it by adding a require_once('vendor/autoload.php'); at the top of the test class
PhPUnit 7.1.0
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
Most helpful comment
This is still broken in 6.5.5, to reproduce uncomment the test at https://github.com/omines/datatables-bundle/blob/1d59c28d43070233c142f479c3894a5dde3da3c3/tests/Unit/Adapter/ElasticaTest.php#L102-L114