Call to undefined method getName when running PHPUnit tests on Drupal 11

Created on 2 July 2024, 5 months ago
Updated 8 August 2024, 4 months ago

Problem/Motivation

When running PHPUnit tests on Drupal 11 for the scheduler module, it throws below error:

Error: Call to undefined method Drupal\Tests\scheduler\Functional\SchedulerPermissionsTest::getName()

/Users/user1/drupal11.0.0-beta1/docroot/modules/contrib/scheduler/tests/src/Functional/SchedulerBrowserTestBase.php:59
/Users/user1/drupal11.0.0-beta1/docroot/modules/contrib/scheduler/tests/src/Functional/SchedulerPermissionsTest.php:48

Steps to reproduce

  • Setup a Drupal 11 project.
  • Download the Scheduler module.
  • Run PHPUnit tests against it and you'll see above error.

Proposed resolution

The reason it thorws above error, because the setup() function in SchedulerBrowserTestBase.php invokes $this->getName(), the getName function exists until PHPUnit 9.5, but it doesn't exists on PHPUnit 10.
So, as an alternative, we should use $this->toString() method.

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India vishalkhode

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

Merge Requests

Comments & Activities

  • Issue created by @vishalkhode
  • First commit to issue fork.
  • Merge request !152Fix missing method issue. → (Merged) created by deepakkm
  • Pipeline finished with Success
    5 months ago
    Total: 5828s
    #213566
  • Pipeline finished with Canceled
    5 months ago
    #213648
  • Pipeline finished with Failed
    5 months ago
    Total: 7598s
    #213650
  • Pipeline finished with Failed
    5 months ago
    Total: 710s
    #213850
  • Pipeline finished with Failed
    5 months ago
    Total: 274s
    #214729
  • Pipeline finished with Success
    5 months ago
    #214733
  • Status changed to Needs review 5 months ago
  • Status changed to RTBC 5 months ago
  • 🇮🇳India vishalkhode

    Reviewed changes and looks good to me.

  • 🇬🇧United Kingdom jonathan1055

    Changed parent to related issue.

    The phpunit tests all fail at D11. That is not necessarily the fault of this MR, but the overall 'next major' testing needs to be sorted out before I can release a Drupal 11 compatible version of Scheduler.

  • Pipeline finished with Failed
    4 months ago
    Total: 55s
    #230892
  • Pipeline finished with Failed
    4 months ago
    Total: 659s
    #230897
  • 🇮🇳India vishalkhode

    Hi @jonathan1055
    Yes, there are couple of Drupal 11 tests failing (not all). I've described the complete Drupal 11 status here 📌 Automated Drupal 11 compatibility fixes for scheduler Active . Also, I've added some commits in 📌 Automated Drupal 11 compatibility fixes for scheduler Active to run PHPUnit tests on Drupal 11. Can we merge changes for this ticket as we need to fix this for Drupal 11.

    The phpunit tests all fail at D11. That is not necessarily the fault of this MR, but the overall 'next major' testing needs to be sorted out before I can release a Drupal 11 compatible version of Scheduler.

  • Pipeline finished with Success
    4 months ago
    Total: 547s
    #231335
  • Pipeline finished with Success
    4 months ago
    Total: 2923s
    #232948
  • 🇬🇧United Kingdom jonathan1055

    Thanks for making this MR. Just checked locally and using toString() actually provides more information than we had before.

    getName() returns testViewScheduledContentOverview with data set "#commerce_product"

    toString() returns Drupal\Tests\scheduler\Functional\SchedulerViewsAccessTest::testViewScheduledContentOverview with data set "#commerce_product" ('commerce_product', 'test_product')

    But this should not affect the outcome of the stristr() condition

  • Pipeline finished with Skipped
    4 months ago
    #233745
  • Status changed to Fixed 4 months ago
  • 🇬🇧United Kingdom jonathan1055

    Previously we had errors in PHPstan

      Line   tests/src/Functional/SchedulerBrowserTestBase.php                       
     ------ ------------------------------------------------------------------------ 
      59     Call to an undefined method                                             
             Drupal\Tests\scheduler\Functional\SchedulerBrowserTestBase::getName().  
    

    etc,
    and with this MR the PHPstan Next Major is green and clean.

    The PHPUnit tests also all had

    Error: Call to undefined method
    Drupal\Tests\scheduler\Functional\the-test-name::getName()
    

    and these are now solved with this MR.

    Also, the tests pass at Current and Previous Major (so we maintain backwards compatibility with Drupal 9.5)

    Thank you @deepakkm and @vishalkhode. Merged and fixed.

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

Production build 0.71.5 2024