Problem/Motivation

All unit tests in tests/src/Unit/SchemaMetatagManagerTest.php are currently failing/skipped due to data providers not being defined as static.

Considering that this issue affects all unit tests in all open merge requests I would consider it important.

Note: I discovered this while writing tests for #3411824: Allow for default values of "0" (int) zero and included the fix in that MR but it makes more sense to resolve this in a dedicated issue and have all other MRs benefit from it.

Steps to reproduce

Phpunit jobs report the following:

PHPUnit\Event\Test\PhpunitErrorTriggered: The data provider specified for Drupal\Tests\schema_metatag\Unit\SchemaMetatagManagerTest::testPivot is invalid
Data Provider method Drupal\Tests\schema_metatag\Unit\SchemaMetatagManagerTest::pivotData() is not static

Above error is repeated 8 times, each time for a different test. And at the end there is the following:

PHPUnit\Event\TestRunner\WarningTriggered: No tests found in class "Drupal\Tests\schema_metatag\Unit\SchemaMetatagManagerTest".

Note that, although all these errors are listed in the report, phpunit job is still marked green (Passed).

Phpstan analysis reports the following:

@dataProvider pivotData related method must be static in PHPUnit 10
and newer.
🪪 phpunit.dataProviderStatic

Similar errors are repeated 8 times.

Proposed resolution

Define all data providers as static.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vaish created an issue. See original summary.

vaish’s picture

Assigned: vaish » Unassigned
Issue summary: View changes
Status: Active » Needs review

Merge request adds static keyword to all data provider methods.

You can see that all Unit tests now pass (lines 194-236 in the report).

And phpstan doesn't report any errors in tests/src/Unit/SchemaMetatagManagerTest.php file.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

@vaish maybe you'd like to also fix the other code quality warnings here?

Code Quality scans found 4 new findings

RTBC in general.

vaish’s picture

Thanks for the review, @anybody.

@vaish maybe you'd like to also fix the other code quality warnings here?

Other code quality issues are unrelated to fixing unit tests. I would rather not mix unrelated changes into this MR.

Btw, I'm not sure why the message claims "it found 4 new findings". I don't see how any of those could have been introduced by this MR.

anybody’s picture

@vaish thanks! I created #3617092: Fix phpstan and phpcs

Maybe you'd also like to participate there?

anybody’s picture

Version: 3.0.x-dev » 3.1.x-dev

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

vaish’s picture

@vaish thanks! I created #3617092: Fix phpstan and phpcs

Maybe you'd also like to participate there?

Thanks, @anybody. I'm quite busy now and won't be able to participate. Maybe some time later if the issue is still open.

Status: Fixed » Closed (fixed)

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