PHPUnit fails when a possible contrib extension directory doesn't exist

Created on 18 September 2024, 3 months ago

Problem/Motivation

PHPUnit throws an unhandled exception if one of the first six directories in drupal_phpunit_contrib_extension_directory_roots() doesn't exist.

PHPUnit 9.6.20 by Sebastian Bergmann and contributors.

Error in bootstrap script: UnexpectedValueException:
RecursiveDirectoryIterator::__construct(/opt/drupal/web/profiles): Failed to open directory: No such file or directory
#0 /opt/drupal/web/core/tests/bootstrap.php(24): RecursiveDirectoryIterator->__construct('/opt/drupal/web...', 16384)
#1 [internal function]: drupal_phpunit_find_extension_directories('/opt/drupal/web...')
#2 /opt/drupal/web/core/tests/bootstrap.php(131): array_map('drupal_phpunit_...', Array)
#3 /opt/drupal/web/core/tests/bootstrap.php(143): drupal_phpunit_populate_class_loader()
#4 /opt/drupal/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('/opt/drupal/web...')
#5 /opt/drupal/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/opt/drupal/web...')
#6 /opt/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php(567): PHPUnit\Util\FileLoader::checkAndLoad('/opt/drupal/web...')
#7 /opt/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php(347): PHPUnit\TextUI\Command->handleBootstrap('/opt/drupal/web...')
#8 /opt/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php(114): PHPUnit\TextUI\Command->handleArguments(Array)
#9 /opt/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run(Array, true)
#10 /opt/drupal/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#11 /opt/drupal/vendor/bin/phpunit(122): include('/opt/drupal/ven...')
#12 {main}

Steps to reproduce

In composer.json's "drupal-scaffold" section, disable scaffolding the profiles README.txt file:

        "drupal-scaffold": {
            "locations": {
                "web-root": "web"
            },
            "file-mapping": {
                "[web-root]/profiles/README.txt": false
            }
        }

Run composer install.

Or alternatively to all that, manually delete the web/profiles directory.

Then, run phpunit tests.

Proposed resolution

Filter the initial six paths set in drupal_phpunit_contrib_extension_directory_roots() to only directories that exist.

🐛 Bug report
Status

Needs review

Version

11.0 🔥

Component
PHPUnit 

Last updated 32 minutes ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024