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

Empty test case class causes error in TestDox XML logger #4630

Closed
djbusby opened this issue Mar 22, 2021 · 1 comment
Closed

Empty test case class causes error in TestDox XML logger #4630

djbusby opened this issue Mar 22, 2021 · 1 comment
Assignees
Labels
feature/test-runner CLI test runner type/bug Something is broken

Comments

@djbusby
Copy link

djbusby commented Mar 22, 2021

Q A
PHPUnit version 9.5.3
PHP version 7.3.27-1~deb10u1
Installation Method Composer

Summary

I made an empty test case, which generally throws some error now it barfs.
No output file from PHPUnit is made either.

Current behavior & How to reproduce

Make a test case like this one:

class Crappy_Test extends \PHPUnit\Framework\TestCase
{
}

Then run PHPUnit and you'll get this output:

PHP Warning:  Invalid argument supplied for foreach() in /[redacted]/vendor/phpunit/phpunit/src/Util/TestDox/XmlResultPrinter.php on line 193
Method PHPUnit\Framework\WarningTestCase::Warning() does not exist

And running with xdebug enabled gives this

PHP Warning:  Invalid argument supplied for foreach() in /[redacted]/vendor/phpunit/phpunit/src/Util/TestDox/XmlResultPrinter.php on line 193
PHP Stack trace:
PHP   1. {main}() /[redacted]/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /[redacted]/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run() /[redacted]/vendor/phpunit/phpunit/src/TextUI/Command.php:96
PHP   4. PHPUnit\TextUI\TestRunner->run() /[redacted]/vendor/phpunit/phpunit/src/TextUI/Command.php:143
PHP   5. PHPUnit\Framework\TestSuite->run() /[redacted]/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:667
PHP   6. PHPUnit\Framework\TestSuite->run() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
PHP   7. PHPUnit\Framework\TestSuite->run() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
PHP   8. PHPUnit\Framework\WarningTestCase->run() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
PHP   9. PHPUnit\Framework\TestResult->run() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestCase.php:884
PHP  10. PHPUnit\Framework\TestResult->endTest() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestResult.php:971
PHP  11. PHPUnit\Util\TestDox\XmlResultPrinter->endTest() /[redacted]/vendor/phpunit/phpunit/src/Framework/TestResult.php:446
Method PHPUnit\Framework\WarningTestCase::Warning() does not exist

Expected behavior

I expected it to just emit a warning, or write a warning about the empty test case to my log file (junit logger).

If I add a function to the class, eg test_something() that is empty, then it passes through no problem and writes that this test is Risky

I think PHPUnit should not abruptly stop when a TestCase script file has zero functions that are test* types. It should tell me I'm doing it wrong in the output file, like with other Risky or Warnings.

@djbusby djbusby added the type/bug Something is broken label Mar 22, 2021
@sebastianbergmann sebastianbergmann self-assigned this Mar 23, 2021
@sebastianbergmann sebastianbergmann added the feature/test-runner CLI test runner label Mar 23, 2021
@sebastianbergmann
Copy link
Owner

Test.php

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

final class Test extends TestCase
{
}
$ phpunit Test.php
PHPUnit 9.5.3-5-gaad51c070 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 00:00.019, Memory: 4.00 MB

There was 1 warning:

1) Warning
No tests found in class "Test".

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
$ phpunit --testdox-xml testdox.xml Test.php
PHPUnit 9.5.3-5-gaad51c070 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)
Warning: foreach() argument must be of type array|object, null given in /usr/local/src/phpunit/src/Util/TestDox/XmlResultPrinter.php on line 193
Method PHPUnit\Framework\WarningTestCase::Warning() does not exist

@sebastianbergmann sebastianbergmann changed the title Empty Test Case Warning Throws Error Empty test case class causes error in TestDox XML logger Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants