Skip to content

PHPUnit 9.x breaks loading of PSR-0/PEAR style classes #5020

Closed
@totten

Description

@totten
Q A
PHPUnit version 9.5.21
PHP version 7.4.26
Installation Method PHAR

Summary

PHPUnit 9.x breaks support for loading classes that use _-based naming.

For example (https://github.com/totten/phpunit-underscore-namespace), if you have a class CRM_Utils_String, then you would want a corresponding test-class CRM_Utils_StringTest.

As is typical in PSR-0 and earlier PEAR-based conventions, the underscores are mapped to folders. The example project has typical filenames like:

  • CRM/Utils/String.php
  • tests/phpunit/CRM/Utils/StringTest.php

Current behavior

Command Result
phpunit9 Runs without error or warning
phpunit9 path/to/test/folder/ Runs with warning
phpunit9 path/to/test/file.php Fails

Full output reproduced at https://github.com/totten/phpunit-underscore-namespace#running-with-phpunit-9

How to reproduce

Checkout the example https://github.com/totten/phpunit-underscore-namespace

Expected behavior

Command Result
phpunit9 Runs without error or warning
phpunit9 path/to/test/folder/ Runs without error or warning
phpunit9 path/to/test/file.php Runs without error or warning

You can similar/expected output when running PHPUnit 8.x, eg https://github.com/totten/phpunit-underscore-namespace#running-with-phpunit-8

Discussion

The changelog (https://phpunit.de/announcements/phpunit-9.html) reports some known breaking changes:

  • (Removed) Support for using class name as CLI argument
  • (Removed) Support for declaring more that one test case class in test source file

However, it's important to note that the example here does not implicate either of these:

  • The tests are executed based on file-names (not class-names).
  • There is only one test-class in each source file. The file-names are consistent with well-known conventions (supported by PSR-0 and earlier PEAR conventions).

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