phpunit: Warnings do not appear in output or in JUnit logfiles

Warnings in PHPUnit 10 appear in the stats at the bottom of summary Tests: 1, Assertions: 1, Warnings: 1. but without details neither in STDOUT nor in JUnit logs.

Test

class MyWarningTest extends TestCase
{
    public function testWarning(): void
    {
        trigger_error('MyWarning', E_USER_WARNING);
        self::assertCount(1, [1]);
    }
}

PHPUnit 9

Output

PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)


Time: 00:00.038, Memory: 8.00 MB

There was 1 error:

1) MyWarningTest::testWarning
MyWarning

/MyWarningTest.php:34

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

JUnit log

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="MyWarningTest" file="/MyWarningTest.php" tests="1" assertions="0" errors="1" warnings="0" failures="0" skipped="0" time="0.001784">
    <testcase name="testWarning" class="MyWarningTest" classname="MyWarningTest" file="/MyWarningTest.php" line="32" assertions="0" time="0.001784">
      <error type="PHPUnit\Framework\Error\Warning">MyWarningTest::testWarning
MyWarning

/MyWarningTest.php:34</error>
    </testcase>
  </testsuite>
</testsuites>

PHPUnit 10.0-g6333dfcaa

Output

PHPUnit 10.0-g6333dfcaa by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.1

.                                                                   1 / 1 (100%)

Time: 00:00.059, Memory: 6.00 MB

OK, but some tests have issues!
Tests: 1, Assertions: 1, Warnings: 1.

JUnit log

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="MyWarningTest" file="/MyWarningTest.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="0.001341">
    <testcase name="testWarning" file="/MyWarningTest.php" line="32" class="MyWarningTest" classname="MyWarningTest" assertions="1" time="0.001341"/>
  </testsuite>
</testsuites>

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

The fact that warnings do not appear in the output by default is by design and intentional: you have to use --display-warnings or displayDetailsOnTestsThatTriggerWarnings="true".

I am not sure whether warnings should be included in the JUnit XML logfile.

anyone else hitting this thread

I found that testdox output seems to prevent warnings info from being displayed. This seems to be the case if its either via XML config or CLI flag

disabling testdox allows warnings etc to be displayed

The fact that warnings do not appear in the output by default is by design and intentional: you have to use --display-warnings or displayDetailsOnTestsThatTriggerWarnings="true".

Oh I see, nice then 👍

I am not sure whether warnings should be included in the JUnit XML logfile.

I’ve seen that warnings are missing from Teamcity logs too. Tools leverage log files to collect and consume PHPUnit results, so I’d say that log files should contain everything needed to report any feedback available.