PHPUnit 10 with Drupal 10

Created on 6 March 2023, almost 2 years ago
Updated 8 January 2024, 12 months ago

Problem/Motivation

Errors occur when using the latest stable version of PHPUnit 10 (which requires PHP 8.1) on Drupal 10.0.x. They are detailed below in the code comments.

Steps to reproduce

Install by using composer require --dev : drupal/core-dev, phpunit/phpunit, phpspec/prophecy-phpunit, symfony/phpunit-bridge, behat/mink

Remaining tasks

I was able to bypass the encountered errors by modifying 2 files :

- web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php

      /*
       *  Warning: Class "Drupal\TestTools\PhpUnitCompatibility\PhpUnit10\TestCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php on line 10
       *  Fatal error: Trait "Drupal\Tests\PhpUnitCompatibilityTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/UnitTestCase.php on line 27
       */
      //class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit" . RunnerVersion::getMajor() . "\TestCompatibilityTrait", 'Drupal\Tests\PhpUnitCompatibilityTrait');
      class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit9\TestCompatibilityTrait", 'Drupal\Tests\PhpUnitCompatibilityTrait');

- web/core/tests/Drupal/Tests/UnitTestCase.php

      /*
       * Fatal error: Trait "Prophecy\PhpUnit\ProphecyTrait" not found in /var/www/html/web/core/tests/Drupal/Tests/UnitTestCase.php on line 27
       */
      //use Prophecy\PhpUnit\ProphecyTrait;
       ...
      //use ProphecyTrait;

This just allows you to run unit tests without errors, but it requires work to make the versions compatible.

๐Ÿ’ฌ Support request
Status

Closed: duplicate

Version

10.0 โœจ

Component
PHPUnitย  โ†’

Last updated about 21 hours ago

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance benjbmc

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    This comes up in google results ahead of the current issue at ๐ŸŒฑ [meta] Support PHPUnit 10 in Drupal 11 Active so cross-linking.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia hiramanpatil

    @benJBmC,
    I am using Drupal 10.1.7 version with below PHPUnit configuration.

    "require-dev": {
    "phpspec/prophecy": "^1.17",
    "phpunit/phpunit": "9.5.28",
    "symfony/phpunit-bridge": "^7.0"
    }

    I am trying to run the dev module test but getting errors.

    Command - vendor/bin/phpunit web/modules/contrib/devel/tests/src/Functional/DevelControllerTest.php

    Output

    PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

    Testing Drupal\Tests\devel\Functional\DevelControllerTest
    E 1 / 1 (100%)

    Time: 00:48.149, Memory: 10.00 MB

    There was 1 error:

    1) Drupal\Tests\devel\Functional\DevelControllerTest::testRouteGeneration
    Error: Class "Behat\Mink\Driver\BrowserKitDriver" not found

    C:\xampp\htdocs\projects\drupalten\web\core\tests\Drupal\Tests\BrowserTestBase.php:310
    C:\xampp\htdocs\projects\drupalten\web\core\tests\Drupal\Tests\BrowserTestBase.php:222
    C:\xampp\htdocs\projects\drupalten\web\core\tests\Drupal\Tests\BrowserTestBase.php:370
    C:\xampp\htdocs\projects\drupalten\web\modules\contrib\devel\tests\src\Functional\DevelBrowserTestBase.php:43
    C:\xampp\htdocs\projects\drupalten\web\modules\contrib\devel\tests\src\Functional\DevelControllerTest.php:57
    C:\xampp\htdocs\projects\drupalten\vendor\phpunit\phpunit\src\Framework\TestResult.php:728

    ERRORS!
    Tests: 1, Assertions: 1, Errors: 1.

    Remaining self deprecation notices (1)

    1x: The Drupal\Tests\devel\Functional\DevelControllerTest::$modules property must be declared protected. See https://www.drupal.org/node/2909426 โ†’
    1x in DrupalListener::startTest from Drupal\Tests\Listeners

Production build 0.71.5 2024