Skip to content

Commit

Permalink
Do not emit Test\ConsideredRisky event twice when a test is run in is…
Browse files Browse the repository at this point in the history
…olated process
  • Loading branch information
sebastianbergmann committed Jun 15, 2022
1 parent 850bd7f commit cbd0ac1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/Util/PHP/AbstractPhpProcess.php
Expand Up @@ -27,7 +27,6 @@
use function unserialize;
use __PHP_Incomplete_Class;
use ErrorException;
use PHPUnit\Event;
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\Code\Throwable;
use PHPUnit\Event\Facade;
Expand Down Expand Up @@ -360,11 +359,6 @@ static function ($errno, $errstr, $errfile, $errline): void
$test,
$riskyException,
);

Event\Facade::emitter()->testConsideredRisky(
$test->valueObjectForEvents(),
$riskyException->getMessage()
);
} elseif (!empty($skipped)) {
$result->addFailure(
$test,
Expand Down
43 changes: 43 additions & 0 deletions tests/end-to-end/event/test-risky-no-assertions-isolation.phpt
@@ -0,0 +1,43 @@
--TEST--
The right events are emitted in the right order for a test that is run in an isolated process and is considered risky because it did not perform assertions
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
print "skip: this test does not work on Windows / GitHub Actions\n";
}
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--process-isolation';
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/RiskyBecauseNoAssertionsTest.php';

require __DIR__ . '/../../bootstrap.php';

PHPUnit\TextUI\Application::main(false);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
Test Runner Started (PHPUnit %s using %s)
Test Runner Configured
Test Suite Loaded (1 test)
Test Suite Sorted
Event Facade Sealed
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest::testOne)
Test Prepared (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest::testOne)
Test Passed (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest::testOne)
Test Considered Risky (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest::testOne)
This test did not perform any assertions
Test Finished (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest::testOne)
Test Suite Finished (PHPUnit\TestFixture\Event\RiskyBecauseNoAssertionsTest, 1 test)
Test Runner Execution Finished
Test Runner Finished

0 comments on commit cbd0ac1

Please sign in to comment.