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

Test class run in a separate PHP process are passing when "exit" called inside #3968

Merged
merged 3 commits into from Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Util/PHP/AbstractPhpProcess.php
Expand Up @@ -11,6 +11,7 @@

use __PHP_Incomplete_Class;
use ErrorException;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\SyntheticError;
use PHPUnit\Framework\Test;
Expand Down Expand Up @@ -248,6 +249,14 @@ private function processChildResult(Test $test, TestResult $result, string $stdo

$childResult = \unserialize(\str_replace("#!/usr/bin/env php\n", '', $stdout));
\restore_error_handler();

if ($childResult === false) {
$result->addFailure(
$test,
new AssertionFailedError('Test was run in child process and ended unexpectedly'),
$time
);
}
} catch (ErrorException $e) {
\restore_error_handler();
$childResult = false;
Expand Down
29 changes: 29 additions & 0 deletions tests/_files/SeparateProcessesTest.php
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

/**
* @runTestsInSeparateProcesses
*/
class SeparateProcessesTest extends TestCase
{
public function testFoo(): void
{
$this->assertTrue(true);
exit(0);
}

public function testBar(): void
{
$this->assertTrue(true);
$this->assertTrue(true);
exit(1);
}
}
26 changes: 26 additions & 0 deletions tests/end-to-end/separate-processes-test.phpt
@@ -0,0 +1,26 @@
--TEST--
phpunit --no-configuration ../../_files/SeparateProcessesTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = __DIR__ . '/../_files/SeparateProcessesTest.php';

require __DIR__ . '/../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

FF 2 / 2 (100%)

Time: %s, Memory: %s

There were 2 failures:

1) SeparateProcessesTest::testFoo
Test was run in child process and ended unexpectedly

2) SeparateProcessesTest::testBar
Test was run in child process and ended unexpectedly

FAILURES!
Tests: 2, Assertions: 0, Failures: 2.