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.

Issue fork drupal-3475352

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

david.muffley created an issue. See original summary.

david.muffley’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Seems like something that probably would need test coverage.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.