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

Callback throws a TypeError when checking a callable has variadic parameters #5946

Closed
ziadoz opened this issue Sep 10, 2024 · 3 comments
Closed
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11

Comments

@ziadoz
Copy link
Contributor

ziadoz commented Sep 10, 2024

Q A
PHPUnit version 11.3.4
PHP version 8.3.7
Installation Method Composer

Summary

I think recent changes to the Callback class to handle variadic parameters are causing this type error:

TypeError: ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, class@anonymous given

Current behavior

The Callback class accepts a callable but it passes that to ReflectionFunction, which only accepts a Closure.

How to reproduce

You can reproduce it by directly calling the Callback class with a callable and then calling the isVariadic method:

$callback = new Callback(new class {
    public function __invoke(): void
    {
    }
});
$callback->isVariadic();

Expected behavior

The callable should be converted to a closure before being passed to ReflectionFunction.

I do have a branch open that fixes the issue. If it looks acceptable I can open a PR for it: https://github.com/sebastianbergmann/phpunit/compare/main...ziadoz:phpunit:fix-callback-callable-variadic?expand=1

@ziadoz ziadoz added the type/bug Something is broken label Sep 10, 2024
@kubawerlos
Copy link
Contributor

The changes on your branch look very good.

@ziadoz
Copy link
Contributor Author

ziadoz commented Sep 10, 2024

@kubawerlos Thanks. I've opened a PR with the fix: #5947

@sebastianbergmann sebastianbergmann added feature/assertion Issues related to assertions and expectations version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 labels Sep 11, 2024
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Sep 11, 2024

Thank you.

In the future, please target the appropriate branch for bug fixes. I have cherry-picked your commits to 10.5 and merged them to 11.3 and main from there.

Sorry, this should have gone into a comment on the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants