Repeatable
Always

Steps to repeat
1. clone git@git.drupal.org:project/drupal.git
2. checkout branch 9.0.x
3. run unit test: cd core && ../vendor\bin\phpunit

Expected Results
Tests run as usual

Actual Results
Warning: include(): Failed opening '{path}\core\tests\Drupal\TestTools\PhpUnitCompatibility\PhpUnit8/../../../../../../sites/simpletest/TestCase.php' for inclusion (include_path='{path}\vendor/pear/archive_tar;{path}\vendor/pear/console_getopt;{path}\vendor/pear/pear-core-minimal/src') in {path}\core\tests\Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter.php on line 51

PHP Fatal error: Declaration of Drupal\Tests\UnitTestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in C:\Projects\_poc\_drupal\core\tests\Drupal\Tests\UnitTestCase.php on line 19

Cause
The "simpletest" folder does not exist under the sites/ directory

Patch from user mondrake https://www.drupal.org/project/drupal/issues/3063887#comment-13465642 which first creates the folder if it does not exist seems to solve the issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slootjes created an issue. See original summary.

longwave’s picture

andypost’s picture

Status: Reviewed & tested by the community » Needs review
chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me.

We have this error also in our travis tests, see https://travis-ci.org/BurdaMagazinOrg/module-length-indicator/jobs/65793...

After applying this patch, our tests are working, see https://travis-ci.org/BurdaMagazinOrg/module-length-indicator/jobs/65812...

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php
@@ -43,8 +43,13 @@ public static function mutateTestBase($autoloader) {
+    // Create directory when necessary.
+    $simpletest_directory = __DIR__ . '/../../../../../../sites/simpletest';
+    if (!file_exists($simpletest_directory)) {
+      mkdir($simpletest_directory, 0777, TRUE);
+    }
     // Only write when necessary.
+    $filename = $simpletest_directory . '/TestCase.php';

My one concern with this is race conditions and multiple file_exists checks. We can do a bit better here.

    $simpletest_directory = __DIR__ . '/../../../../../../sites/simpletest';
    // Only write when necessary.
    $filename = $simpletest_directory . '/TestCase.php';
    if (!file_exists($filename) || md5_file($filename) !== md5($alteredCode)) {
      // Create directory when necessary.
      if (!file_exists($simpletest_directory)) {
        mkdir($simpletest_directory, 0777, TRUE);
      }
      file_put_contents($filename, $alteredCode);
    }

So once the file exists - we will only do one file_exists() check.

alexpott credited mondrake.

alexpott’s picture

Crediting @mondrake because they supplied the original patch in a different issue.

swatichouhan012’s picture

Status: Needs work » Needs review
FileSize
1.36 KB
1.06 KB

updated patch wrt comment #5, kindly review new patch.

longwave’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php
@@ -43,9 +43,15 @@ public static function mutateTestBase($autoloader) {
+    // Create directory when necessary.

This comment now appears twice.

swatichouhan012’s picture

Status: Needs work » Needs review
FileSize
1.32 KB
905 bytes

Removed unwanted comment, kindly review new patch.

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

I applied the latest patch to our testing and it still looks good: https://travis-ci.org/github/BurdaMagazinOrg/module-length-indicator/job...

All concerns are fixed, so re-rtbc

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 449b333 and pushed to 9.0.x. Thanks!

  • alexpott committed 449b333 on 9.0.x
    Issue #3114041 by swatichouhan012, longwave, chr.fritsch, alexpott,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

SerShevchyk’s picture

FileSize
1.22 KB
gigimaor’s picture

Hi
I still have compatibility issues with Test Kernel on Drupal v9.5.7 and PHPUnit v9.6.6.
Suggesting this patch

gigimaor’s picture

emb03’s picture

Having this issue on drupal 10.x patch is not applying.