Add appropriate return typehints to all @dataProvider methods

Created on 14 February 2024, 10 months ago
Updated 4 July 2024, 6 months ago

Problem/Motivation

Follow-up to #3353210-37: [PHPUnit 10] @dataProvider methods must be declared static and public โ†’ .

Data providers methods to tests should have an appropriate typehint: array or iterable depending on the test approach.

Maybe the script developed in ๐Ÿ“Œ [PHPUnit 10] @dataProvider methods must be declared static and public Fixed could be reused for the purpose.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
PHPUnitย  โ†’

Last updated about 14 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

  • Issue created by @mondrake
  • First commit to issue fork.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm
  • Assigned to ankitv18
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    Will add missing typehint to dataProviders method.

  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    Added a typehint for dataProviders as array and \Generator wherever yield is used as return.

  • Pipeline finished with Failed
    6 months ago
    Total: 181s
    #206056
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR has some failures.

  • Pipeline finished with Success
    6 months ago
    Total: 511s
    #206185
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    sorry it was my bad, Now pipelines are green, hence moving into review.

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

    Added a typehint for dataProviders as array and \Generator wherever yield is used as return.

    The issue summary suggests that generators should have the iterable typehint. So either we should update the issue summary or change \Generator to iterable.

    Also found a few missing:

    • All tests that extend \Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase have a providerSource method
    • \Drupal\Tests\layout_builder\Unit\SectionTest::providerTestGetThirdPartySettings
  • Pipeline finished with Success
    6 months ago
    Total: 617s
    #206424
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    I think I have all missing return types for the @dataProviders.
    @mstrelan for iterable or generator should be as a typehint , I'll left this for a discussion.
    And Isn't the all iterable is a generator? So bit confused here as most of the place \Generator is mentioned the comment block of the provider method.

    cc: @xjm @mondrake @mustgrave

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

    I think itโ€™s more accurate to typehint \Generator where yield is used.

    iterable is an alias for array|\Traversable which means itโ€™s the most generic typehint possible. See https://www.php.net/manual/en/language.types.iterable.php

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    Yes, All iterable's is a generator.
    With the @mondrake comment#11 I'm moving this issue into review.
    as per @mstrelan comment#9 summary needs to be updated.

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    If summary needs to be updated then it should be NW

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Given #11 maybe all data providers should be iterable? It makes no difference for the purposes of the test whether it returns an array or uses a generator, and iterable allows us to use either and swap between them freely.

  • First commit to issue fork.
  • Pipeline finished with Success
    6 months ago
    Total: 540s
    #215896
Production build 0.71.5 2024