Skip to content

PHPUnit does not verify its own PHP extension requirements #4720

@jrfnl

Description

@jrfnl
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 😂

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions