Problem/Motivation
Discovered in #3211131: Call to an undefined static method PHPUnit\Util\ErrorHandler::handleError() in DrupalStandardsListenerTrait, PhpUnitCliTest::testFunctionalTestDebugHtmlOutput() fails if BROWSERTEST_OUTPUT_DIRECTORY is an empty string:
1) Drupal\Tests\Core\Test\PhpUnitCliTest::testFunctionalTestDebugHtmlOutput
Failed asserting that 'PHPUnit 9.5.11 by Sebastian Bergmann and contributors.\n
\n
Runtime: PHP 8.0.13\n
Configuration: /var/www/html/drupal/core/phpunit.xml.dist\n
\n
Testing Drupal\Tests\image\Functional\ImageDimensionsTest\n
. 1 / 1 (100%)\n
\n
Time: 00:05.966, Memory: 4.00 MB\n
\n
OK (1 test, 60 assertions)\n
' contains "HTML output was generated".
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/drupal/core/tests/Drupal/Tests/Core/Test/PhpUnitCliTest.php:52
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:678
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:678
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:678
/var/www/html/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:678
/var/www/html/drupal/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:670
/var/www/html/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:143
/var/www/html/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:96
The test attempts to skip if the variable is not set, but this is too strict:
if (getenv('BROWSERTEST_OUTPUT_DIRECTORY') === FALSE) {
$this->markTestSkipped('This test requires the environment variable BROWSERTEST_OUTPUT_DIRECTORY to be set.');
}
In reality HtmlOutputPrinterTrait checks for it being truthy only, so an empty string produces no output:
if ($html_output_directory = getenv('BROWSERTEST_OUTPUT_DIRECTORY')) {
Steps to reproduce
BROWSERTEST_OUTPUT_DIRECTORY= vendor/bin/phpunit -c core core/tests/Drupal/Tests/Core/Test/PhpUnitCliTest.php
Proposed resolution
Make the check less strict.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
mondrakeThanks for opening the followup @longwave
Since we have this in the HtmlOutputPrinterTrait,
I think we should to the same to check if the test need to be skipped (i.e. ensuring the dir exists and is writable and if not, skip)
Comment #3
longwaveTo me just doing this is enough and fixes the problem at hand. I don't think we should replicate the exact logic in the test - the variable being set, but incorrectly, is an error to me that the test should catch.
Comment #4
mondrakeUhm OK but then we should IMO be a bit more explicit what's failing, so using assertDirectoryExists and assertDirectoryIsWritable?
Comment #6
mondrakeDone something different, does it make sense to enhance the test like this?
Comment #7
longwaveAdditional test coverage is good, that works for me.
Comment #8
alexpottImo we should move testFunctionalTestDebugHtmlOutput to a functional test because it runs functional tests and so has even more requirements than just BROWSERTEST_OUTPUT_DIRECTORY - it'll fail with
Exception: You must provide a SIMPLETEST_BASE_URL environment variable to run some PHPUnit based functional tests.too.Committed 90f9d14 and pushed to 10.0.x. Thanks!
Comment #11
mondrakeFiled #3265459: Move testFunctionalTestDebugHtmlOutput to a functional test for follow up.