Skip to content

Commit

Permalink
Only report test outcome (errored, failed, incomplete, skipped, or pa…
Browse files Browse the repository at this point in the history
…ssed)
  • Loading branch information
sebastianbergmann committed Jan 19, 2023
1 parent dd745da commit 2d45550
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 88 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.0.md
Expand Up @@ -48,6 +48,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
* The `size` attribute of `<test>` elements in the TestDox XML logfile now contains a textual representation instead of a number (`"unknown"` instead of `"-1"`, for instance)
* The JUnit XML logfile now has both `name` and `file` attributes on `<testcase>` elements for PHPT tests
* The JUnit XML logfile no longer has `<system-out>` elements that contains the output printed to `stdout` by a test
* The JUnit XML logfile now only reports test outcome (errored, failed, incomplete, skipped, or passed) and no longer test issues (considered risky, for instance)
* The `forceCoversAnnotation` attribute of the `<phpunit>` element of PHPUnit's XML configuration file has been renamed to `requireCoverageMetadata`
* The `beStrictAboutCoversAnnotation` attribute of the `<phpunit>` element of PHPUnit's XML configuration file has been renamed to `beStrictAboutCoverageMetadata`
* The public methods of `PHPUnit\Framework\Assert` and `PHPUnit\Framework\TestCase` are now `final`
Expand Down
42 changes: 3 additions & 39 deletions src/Logging/JUnit/JunitXmlLogger.php
Expand Up @@ -25,7 +25,6 @@
use PHPUnit\Event\Facade;
use PHPUnit\Event\InvalidArgumentException;
use PHPUnit\Event\Telemetry\HRTime;
use PHPUnit\Event\Test\ConsideredRisky;
use PHPUnit\Event\Test\Errored;
use PHPUnit\Event\Test\Failed;
use PHPUnit\Event\Test\Finished;
Expand Down Expand Up @@ -91,11 +90,11 @@ final class JunitXmlLogger
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
public function __construct(Printer $printer, bool $reportRiskyTests)
public function __construct(Printer $printer)
{
$this->printer = $printer;

$this->registerSubscribers($reportRiskyTests);
$this->registerSubscribers();
$this->createDocument();
}

Expand Down Expand Up @@ -262,22 +261,11 @@ public function testFailed(Failed $event): void
$this->testSuiteFailures[$this->testSuiteLevel]++;
}

/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function testConsideredRisky(ConsideredRisky $event): void
{
$this->handleRisky($event->test(), $event->message());

$this->testSuiteErrors[$this->testSuiteLevel]++;
}

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
private function registerSubscribers(bool $reportRiskyTests): void
private function registerSubscribers(): void
{
Facade::registerSubscribers(
new TestSuiteStartedSubscriber($this),
Expand All @@ -290,10 +278,6 @@ private function registerSubscribers(bool $reportRiskyTests): void
new TestSkippedSubscriber($this),
new TestRunnerExecutionFinishedSubscriber($this),
);

if ($reportRiskyTests) {
Facade::registerSubscriber(new TestConsideredRiskySubscriber($this));
}
}

private function createDocument(): void
Expand Down Expand Up @@ -330,26 +314,6 @@ private function handleFault(Test $test, Throwable $throwable, string $type): vo
$this->currentTestCase->appendChild($fault);
}

/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
private function handleRisky(Test $test, string $message): void
{
assert($this->currentTestCase !== null);

$buffer = $this->testAsString($test) . $message;

$risky = $this->document->createElement(
'error',
Xml::prepareString($buffer)
);

$risky->setAttribute('type', 'PHPUnit\Framework\RiskyTest');

$this->currentTestCase->appendChild($risky);
}

/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
Expand Down
30 changes: 0 additions & 30 deletions src/Logging/JUnit/Subscriber/TestConsideredRiskySubscriber.php

This file was deleted.

1 change: 0 additions & 1 deletion src/TextUI/TestRunner.php
Expand Up @@ -234,7 +234,6 @@ public function run(Configuration $configuration, TestSuite $suite): TestResult
if ($configuration->hasLogfileJunit()) {
new JunitXmlLogger(
$this->printerFor($configuration->logfileJunit()),
$configuration->reportUselessTests()
);
}

Expand Down
12 changes: 3 additions & 9 deletions tests/end-to-end/logging/log-junit-to-file.phpt
Expand Up @@ -26,7 +26,7 @@ unlink($logfile);
--EXPECTF--
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="PHPUnit\SelfTest\Basic\StatusTest" file="%sStatusTest.php" tests="12" assertions="4" errors="4" failures="2" skipped="5" time="%f">
<testsuite name="PHPUnit\SelfTest\Basic\StatusTest" file="%sStatusTest.php" tests="12" assertions="4" errors="2" failures="2" skipped="5" time="%f">
<testcase name="testSuccess" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f"/>
<testcase name="testFailure" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\SelfTest\Basic\StatusTest::testFailure%A
Expand All @@ -46,10 +46,7 @@ RuntimeException:%w
<testcase name="testSkipped" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<skipped/>
</testcase>
<testcase name="testRisky" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<error type="PHPUnit\Framework\RiskyTest">PHPUnit\SelfTest\Basic\StatusTest::testRisky%A
This test did not perform any assertions</error>
</testcase>
<testcase name="testRisky" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f"/>
<testcase name="testSuccessWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f"/>
<testcase name="testFailureWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\SelfTest\Basic\StatusTest::testFailureWithMessage%A
Expand All @@ -70,9 +67,6 @@ RuntimeException: error with custom message
<testcase name="testSkippedWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<skipped/>
</testcase>
<testcase name="testRiskyWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<error type="PHPUnit\Framework\RiskyTest">PHPUnit\SelfTest\Basic\StatusTest::testRiskyWithMessage%A
This test did not perform any assertions</error>
</testcase>
<testcase name="testRiskyWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f"/>
</testsuite>
</testsuites>
12 changes: 3 additions & 9 deletions tests/end-to-end/logging/log-junit-to-stdout.phpt
Expand Up @@ -15,7 +15,7 @@ require_once __DIR__ . '/../../bootstrap.php';
--EXPECTF--
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="PHPUnit\SelfTest\Basic\StatusTest" file="%sStatusTest.php" tests="12" assertions="4" errors="4" failures="2" skipped="5" time="%f">
<testsuite name="PHPUnit\SelfTest\Basic\StatusTest" file="%sStatusTest.php" tests="12" assertions="4" errors="2" failures="2" skipped="5" time="%f">
<testcase name="testSuccess" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f"/>
<testcase name="testFailure" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\SelfTest\Basic\StatusTest::testFailure%A
Expand All @@ -35,10 +35,7 @@ RuntimeException:%w
<testcase name="testSkipped" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<skipped/>
</testcase>
<testcase name="testRisky" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<error type="PHPUnit\Framework\RiskyTest">PHPUnit\SelfTest\Basic\StatusTest::testRisky%A
This test did not perform any assertions</error>
</testcase>
<testcase name="testRisky" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f"/>
<testcase name="testSuccessWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f"/>
<testcase name="testFailureWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="1" time="%f">
<failure type="PHPUnit\Framework\ExpectationFailedException">PHPUnit\SelfTest\Basic\StatusTest::testFailureWithMessage%A
Expand All @@ -59,9 +56,6 @@ RuntimeException: error with custom message
<testcase name="testSkippedWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<skipped/>
</testcase>
<testcase name="testRiskyWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f">
<error type="PHPUnit\Framework\RiskyTest">PHPUnit\SelfTest\Basic\StatusTest::testRiskyWithMessage%A
This test did not perform any assertions</error>
</testcase>
<testcase name="testRiskyWithMessage" file="%sStatusTest.php" line="%d" class="PHPUnit\SelfTest\Basic\StatusTest" classname="PHPUnit.SelfTest.Basic.StatusTest" assertions="0" time="%f"/>
</testsuite>
</testsuites>

0 comments on commit 2d45550

Please sign in to comment.