Support for phpunit 10

Created on 8 July 2025, about 6 hours 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
    about 5 hours 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

Production build 0.71.5 2024