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

NamedArgumentForDataProviderRector only changing the first data provider #345

Closed
gnutix opened this issue Jun 29, 2024 · 6 comments · Fixed by #349
Closed

NamedArgumentForDataProviderRector only changing the first data provider #345

gnutix opened this issue Jun 29, 2024 · 6 comments · Fixed by #349

Comments

@gnutix
Copy link

gnutix commented Jun 29, 2024

Hey there,

I've ran NamedArgumentForDataProviderRector on my project and noticed it only refactors the first #[DataProvider] it encounters. On my project, it missed about a 1/3 of the deprecations.

Changing getDataProviderMethodName to return an array of method names :

    private function getDataProviderMethodNames(ClassMethod $classMethod) : array
    {
        $methodNames = [];
        $attributeClassName = DataProvider::class;
        foreach ($classMethod->attrGroups as $attributeGroup) {
            foreach ($attributeGroup->attrs as $attribute) {
                if (!$this->isName($attribute->name, $attributeClassName)) {
                    continue;
                }
                foreach ($attribute->args as $arg) {
                    if ($arg->value instanceof String_) {
                        $methodNames[] = $arg->value->value;
                    }
                }
            }
        }
        return $methodNames;
    }

and calling it like this :

            $dataProviderMethodNames = $this->getDataProviderMethodNames($classMethod);
            if ($dataProviderMethodNames === []) {
                continue;
            }
            foreach ($dataProviderMethodNames as $dataProviderMethodName) {
                // ... rest of the code untouched
            }

fixes the issue. /cc @marcelthole

gnutix

@TomasVotruba
Copy link
Member

Great 👍 Could you send the PR with fix? :)

@gnutix
Copy link
Author

gnutix commented Jun 29, 2024

Sorry, too much on my plate these days.

@TomasVotruba
Copy link
Member

No worries 👍

Closing as duplicate of similar issue to keep focus: #346 (comment)

@gnutix
Copy link
Author

gnutix commented Jun 30, 2024

Without this fix, the rule is only partially doing its job, and the "optional feature" triggers deprecations that are outputted by PHUnit. So please, don't close this issue, it's a separate problem from the other you've linked.

@TomasVotruba
Copy link
Member

TomasVotruba commented Jun 30, 2024

I missunderstood then. We'll need a failing demo link first.

Ref: #330

/cc @marcelthole

@marcelthole
Copy link
Contributor

I added a failing testcase and fixed that case. We didn't had the case with multiple dataproviders on a single test method. But it should be fixed now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants