Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@dataProvider annotation rejects previously valid method name style #5288

Closed
Crell opened this issue Mar 21, 2023 · 2 comments
Closed

@dataProvider annotation rejects previously valid method name style #5288

Crell opened this issue Mar 21, 2023 · 2 comments
Assignees
Labels
feature/data-provider Data Providers feature/metadata/annotations type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@Crell
Copy link

Crell commented Mar 21, 2023

Q A
PHPUnit version 10.0.17
PHP version 8.1.14
Installation Method Composer

Summary

In PHPUnit 10, the @dataProvider annotation got unexpectedly stricter. Specifically, in previous versions I commonly wrote this:

/**
 * @dataProvider provider()
 */
public function testThing(int $a, int $b) { ... }

public function provider(): iterable { ... }

The () on the end of the provider method was ignored. As of v10, it is no longer ignored. This is going to create... a lot of drudge work changing all of my provider references to remove the ().

Ideally they'd convert to attributes at some point, but annotations are still supported for now and this was an unexpected snag.

Current behavior

The code example above gives an error along the lines of:

1) Crell\Tutorials\RectangleTest::testThing
The data provider specified for Crell\Tutorials\RectangleTest::testThing is invalid
Method Crell\Tutorials\RectangleTest::provider()() does not exist

(Note the double () in what it thinks is the method name, indicating that v10 thinks the () is part of the method name.)

How to reproduce

See code example above.

Expected behavior

As in v9, the () should be stripped off and ignored. Or if that's not feasible, this would be something to mention in the upgrading docs as it's an unexpected break.

@Crell Crell added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Mar 21, 2023
sebastianbergmann added a commit that referenced this issue Mar 21, 2023
@sebastianbergmann sebastianbergmann changed the title dataProvider annotation rejects previously valid method name style @dataProvider annotation rejects previously valid method name style Mar 21, 2023
@sebastianbergmann sebastianbergmann self-assigned this Mar 21, 2023
@Crell
Copy link
Author

Crell commented Mar 21, 2023

Now that's an impressive turnaround! Thanks, @sebastianbergmann! ❤️

@sebastianbergmann
Copy link
Owner

Thank you, Larry, for reporting this. I was not aware (anymore) that @dataProvider method() was supported and we did not have any tests for that. Now we do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers feature/metadata/annotations type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

2 participants