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.
Issue fork schema_metatag-3606525
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
Comment #3
vaish commentedMerge request adds
statickeyword 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.phpfile.Comment #4
anybody@vaish maybe you'd like to also fix the other code quality warnings here?
RTBC in general.
Comment #5
vaish commentedThanks for the review, @anybody.
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.
Comment #6
anybody@vaish thanks! I created #3617092: Fix phpstan and phpcs
Maybe you'd also like to participate there?
Comment #7
anybodyComment #9
anybodyComment #11
vaish commentedThanks, @anybody. I'm quite busy now and won't be able to participate. Maybe some time later if the issue is still open.