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

PHPUnit does not verify its own PHP extension requirements #4720

Closed
jrfnl opened this issue Jun 25, 2021 · 1 comment
Closed

PHPUnit does not verify its own PHP extension requirements #4720

jrfnl opened this issue Jun 25, 2021 · 1 comment
Labels
type/bug Something is broken

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Jun 25, 2021

Q A
PHPUnit version 9.5.5
PHP version All supported
Installation Method PHAR

Summary

It appears that PHPUnit does not (in all cases?) verify whether its own PHP extension requirements have been satisfied.

While for Composer installs, this shouldn't be (much of) an issue as Composer will verify on install, for running PHPUnit via the Phar, however, this can lead to unexpected error notices (without backtrace).

The Composer require section lists the following requirements, though not all of these appear to be "hard" requirements:

phpunit/composer.json

Lines 24 to 30 in fb9b833

"php": ">=7.3",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",

Current behavior

When the Mbstring extension is disabled and a non-testdox test run is requested, all will be fine and the test progress and results display correctly.

However, when the Mbstring extension is disabled and --testdox is used, this will result in a Call to undefined function mb_strtolower() notice being thrown without indication where it's coming from.

Based on a quick code base search, AFAICS this is caused by this function call:

$isLowerCase = mb_strtolower($className[$i], 'UTF-8') === $className[$i];

How to reproduce

  • Make sure the mbstring extension is disabled (from the php.ini file or otherwise).
  • Run the following command using a PHPUnit Phar file on PHPUnit's own test suite and see the tests pass without issues:
phpunit --filter TestBuilderTest
  • Next, run the same command with --testdox enabled:
phpunit --testdox --filter TestBuilderTest
  • See the Call to undefined function mb_strtolower() notice appear without indication of the file it came from (even when Xdebug is turned on) and no test results displayed.

Expected behavior

Either an error before the test run starts saying that the Mbstring extension should be enabled when using the --testdox option or a graceful fall-back to strtolower() when Mbstring is not available.

Extra information

Discovered when testing @requires conditions on an external test, where one of the @requires was for the Mbstring extension 😂

@jrfnl jrfnl added the type/bug Something is broken label Jun 25, 2021
@jrfnl
Copy link
Contributor Author

jrfnl commented Jun 26, 2021

Thanks for the quick response @sebastianbergmann !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant