Support for phpunit 10

Created on 8 July 2025, 21 days ago

Problem/Motivation

I struggle to run all tests because of:

The data provider specified for Drupal\Tests\tfa\Unit\TfaContextTest::testCanLoginWithoutTfa is invalid
Data Provider method Drupal\Tests\tfa\Unit\TfaContextTest::providerCanLoginWithoutTfa() is not static

So some tests are easier to let test runner run which slows down contribution. E.g. I hit this in Provide an alter for user settings Active

E.g. see 📌 [PHPUnit 10] @dataProvider methods must be declared static and public Fixed for background.

Steps to reproduce

Use latest phpunit and attempt to run tests

Proposed resolution

Fix data provider to not use $this

Remaining tasks

Merge request

User interface changes

N/A

API changes

N/A

Data model changes

N/A

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom scott_euser

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

Merge Requests

Comments & Activities

  • Issue created by @scott_euser
  • First commit to issue fork.
  • Merge request !153Update file TfaContextTest.php → (Open) created by immaculatexavier
  • Pipeline finished with Success
    21 days ago
    Total: 356s
    #541533
  • 🇮🇳India immaculatexavier

    Done the below Fixes for PHPUnit 10:

    • Removed usage of $this in static providerCanLoginWithoutTfa().
    • Replaced $this->equalTo() with Assert::equalTo() from PHPUnit\Framework\Assert.
    • Replaced $this->stringContains() with Assert::stringContains().
    • Used UnitTestCase::createStub(TranslationInterface::class) for generating translation stubs inside static context.

    Needs review.

  • 🇬🇧United Kingdom scott_euser

    Thanks! I think still somehow its too strict though. E.g. if I run

    ddev exec -d /var/www/html "./vendor/bin/phpunit -c ./core/phpunit.xml.dist ./modules/contrib/tfa/tests/src/Unit/TfaContextTest.php"
    

    At:

    /var/www/html/modules/contrib/tfa/tests/src/Unit/TfaContextTest.php:430
    

    I get false errors like

    -    'stringTranslation' => MockObject_TranslationInterface_00404523 Object #398 (
    -        '__phpunit_state' => PHPUnit\Framework\MockObject\TestDoubleState Object #433 (
    +    'stringTranslation' => MockObject_TranslationInterface_3106f881 Object #2004 (
    +        '__phpunit_state' => PHPUnit\Framework\MockObject\TestDoubleState Object #2006 (
    

    Which are nearly the same and for the purposes of the test should be considered the same I believe

  • 🇺🇸United States cmlara

    -c ./core/phpunit.xml.dist
    I would suggest to attempt running without the core config to see if this helps your local testing.
    Is this perhaps for a diffrent version of PHPUnit? We do us PHPUnit 10 currently with I belive Drupal Core 11.2 bumping us to 11.2 once GitLab templates updates the target core version.

    We intentionally use --no-configuration in GitLabCi to resolve other issues that core is excessively strict about (such as 3rd party calling deprecated code) that do not apply to contrib and are generally considered the responsibility of PHPStan (core runs L2, we run L9)

    Since these were written I did learn there is a method (register translation service in global container mock) to allow string casts to work which would have possibly allowed me to compare straight strings instead of the translatable object to allow for simpler comparisons.

    We do need to convert to static as I believe it is either PHPUnit 11.5 or 12 that will make that mandatory (this one was missed somewhere in the process) .

    Remaining comment of failures from #5 would need to investigate. I do believe I have seen some asserts will be changing location in PHPUnit 12.

    I see the following in the test run window:

    OK, but there were issues!
    Tests: 197, Assertions: 1648, Warnings: 1, PHPUnit Deprecations: 12.

    IIRC core config fail on deprecation while we would desire not to (items that will need to be changed in the future)

  • 🇬🇧United Kingdom scott_euser

    Yep you're right, phpunit 11 sorry

Production build 0.71.5 2024