Fix string array keys in data sets returned by data provider methods that do not match the parameter names in Kernel tests

Created on 19 April 2024, 8 months ago
Updated 18 May 2024, 7 months ago

Problem/Motivation

PhpUnit 10.5.18 Deprecated support for string array keys in data sets returned by data provider methods that do not match the parameter names: https://github.com/sebastianbergmann/phpunit/blob/10.5/ChangeLog-10.5.md...

See https://github.com/sebastianbergmann/phpunit/pull/5812.

Proposed resolution

Ensure all dataproviders that return associate arrays have the keys reflecting the name of the argument that uses each, in Kernel tests.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
PHPUnitย  โ†’

Last updated about 10 hours ago

Created by

๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • Issue created by @mondrake
  • Merge request !7611Closes #3442167 โ†’ (Closed) created by mondrake
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Failed
    8 months ago
    Total: 194s
    #151425
  • Pipeline finished with Success
    8 months ago
    Total: 1080s
    #151437
  • Pipeline finished with Failed
    8 months ago
    Total: 1198s
    #151484
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pradhumanjainOSL

    pradhumanjain2311 โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    8 months ago
    Total: 993s
    #151602
  • Pipeline finished with Failed
    8 months ago
    Total: 1053s
    #151886
  • Pipeline finished with Failed
    8 months ago
    Total: 1144s
    #151917
  • Pipeline finished with Failed
    8 months ago
    Total: 1022s
    #152029
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Success
    8 months ago
    Total: 1050s
    #152105
  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Success
    8 months ago
    Total: 962s
    #155719
  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Reviewing the changes and they appear to make sense. Assuming these would be caught automatically once we upgrade?

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    Yes, they result in deprecation errors in PHPUnit 10. See test failures in the upgrade issue.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pravesh_poonia

    Updating PHPUnit compatibility due to the deprecation in version 10.5.18, which now requires string array keys in data sets returned by data provider methods to match parameter names in Kernel tests. This change ensures continued compatibility with the latest PHPUnit version and maintains best practices for data provider usage

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    The scope of this MR is kind of big (500ish LOC to review), especially given that one has to open up the file to check that that the parameter names actually match the keys. That said, I don't have a better suggestion, so going ahead with reviewing it now.

    @mondrake I assume you programmatically scanned for these somehow? Could you document it on the issue for posterity?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    If I were to rescope this issue, I would put all the migrate stuff in one issue (since the expected parameters aren't even in the same file), and the rest of the changes in the first issue.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    #11 PHPUnit 10.5.18 triggers a deprecation for any key not matching the test method argument name. We do not see it in this MR but that is visible in the latest test run of ๐Ÿ“Œ Upgrade PHPUnit to 10, drop Symfony PHPUnit-bridge dependency Fixed which is the input to this MR.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    So far, I reviewed all the non-Migrate changes and confirmed that each change matches the expected parameters. I did not check for missed invalid keys.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Paused in my review based on feedback from @larowlan.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    I think we should press ahead on this, so we can get to phpunit 10, but we should open a followup to remove these keys.

    I don't think they provide value like the cases names do.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Tagging for #16.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    #16 is the opposite of #3443535-9: Change @dataprovider to static in SqlContentEntityStorageSchemaTest โ†’ , so before any follow up there needs to be a decision made IMHO. A coding standard issue this one?

    Personally I think they can help in some cases, especially when data providers pass booleans, like @longwave said in the other issue.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    @mondrake Which job is it on the linked issue? (Sorry, GitLab CI is a scavenger hunt sometimes.)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    FWIW I also find keys helpful, so agreed that we need to have a coding-standards-level discussion about it. I just defer to @larowlan in this since he's a framework manager and also involved in coding standards. :)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    For #19, a code snippet showing the fails would also be helpful here.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    I think we need to have the discussion, which is another reason not to hold this up. We can always come back afterwards. I'll add to the agenda for next coding standards meeting.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Thanks @mondrake. So e.g.:

        1) Drupal\KernelTests\Core\Entity\ContentEntityStorageBaseTest::testCreate
        with data set #0 ('test_bundle')
        * Providing invalid named argument $scalar for method
        Drupal\KernelTests\Core\Entity\ContentEntityStorageBaseTest::testCreate()
        is deprecated and will not be supported in PHPUnit 11.0.
        
        * Providing invalid named argument $scalar for method
        Drupal\KernelTests\Core\Entity\ContentEntityStorageBaseTest::testCreate()
        is deprecated and will not be supported in PHPUnit 11.0.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Docblock and signature from the MigrateSqlSourceTestBase base class for several of the updated tests:

     /**
       * Tests the source plugin against a particular data set.
       *
       * @param array $source_data
       *   The source data that the plugin will read. See getDatabase() for the
       *   expected format.
       * @param array $expected_data
       *   The result rows the plugin is expected to return.
       * @param int $expected_count
       *   (optional) How many rows the source plugin is expected to return.
       * @param array $configuration
       *   (optional) Configuration for the source plugin.
       * @param mixed $high_water
       *   (optional) The value of the high water field.
       * @param string|null $expected_cache_key
       *   (optional) The expected cache key.
       *
       * @dataProvider providerSource
       *
       * @requires extension pdo_sqlite
       */
      public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL, $expected_cache_key = NULL) {
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    core/modules/migrate_drupal/tests/src/Kernel/NodeMigrationTypePluginAlterTest.php is weird and breaks the pattern, but that is because testMigrationPluginAlter($type, array $migration_definitions, array $expected) names its parameters in a way that's inconsistent with the above base class.

    I finished reviewing all the files to make sure the new keys match what's expected for the test method parameter.

    I didn't search to validate that all instances have been changed. If any were missed, or additional ones crop up, they'll show up when we adopt PHPUnit 10 and can be cleaned up at that time.

    Untagged for followup since it's been added to the coding standards agenda.

    @pradhumanjain2311, to get credit for resolving a merge conflict, you need to document the merge conflict on the issue. Reference: https://www.drupal.org/about/core/policies/maintainers/how-is-credit-gra... โ†’

    Resolving a merge conflict when rerolling, rebasing, or merging HEAD
    Document the merge conflict diff on the issue in a <code> tag.

    Saving issue credits.

    • xjm โ†’ committed 88b92b94 on 11.x
      Issue #3442167 by mondrake, xjm, larowlan: Fix string array keys in data...
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Committed to 11.x. Thanks! I also cherry-picked it to 10.3.x as a no-op change to tests.

    I considered whether this needed a CR, but since PHPUnit will enforce this for us in the future, there's no needs.

    Thanks everyone!

  • Status changed to Fixed 8 months ago
    • xjm โ†’ committed 29b22a90 on 10.3.x
      Issue #3442167 by mondrake, xjm, larowlan: Fix string array keys in data...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024