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

PHPUnit\Util\Test::parseTestMethodAnnotations() handles a lot of exceptions #4379

Closed
joshua-bn opened this issue Jul 15, 2020 · 3 comments
Closed
Labels
type/bug Something is broken

Comments

@joshua-bn
Copy link

Q A
PHPUnit version 8.5.8
PHP version 7.4.7
Installation Method Composer

Summary

While trying to diagnose an issue with my tests I have run Xdebug. It keeps stopping on an exception that is thrown in PHPUnit\Util\Annotation\Registry::forMethod() because forMethod is passed an empty string and ReflectionMethod() can't find MyClassName::()

Current behavior

This throws a lot of exceptions that are caught. We can improve that.

How to reproduce

Call PHPUnit\Util\Test::parseTestMethodAnnotations() without a second argument

Expected behavior

Don't allow an empty string to be passed to PHPUnit\Util\Annotation\Registry::forMethod(). if ($methodName !== null) { on line 308 should be if (!empty($methodName)) {.

@joshua-bn joshua-bn added the type/bug Something is broken label Jul 15, 2020
@joshua-bn
Copy link
Author

Sorry, this is an enhancement and not really a bug.

@joshuaadickerson
Copy link

@sebastianbergmann just wondering why it was closed.

Thank you for all that you do.

@vemod
Copy link

vemod commented Feb 16, 2023

This is a bug,

public static function parseTestMethodAnnotations(string $className, ?string $methodName = '') : array
    {
        $registry = Registry::getInstance();
        if ($methodName !== null) {
            try {
                return ['method' => $registry->forMethod($className, $methodName)->symbolAnnotations(), 'class' => $registry->forClassName($className)->symbolAnnotations()];
            } catch (\PHPUnit\Util\Exception $methodNotFound) {
                // ignored
            }
        }
        return ['method' => null, 'class' => $registry->forClassName($className)->symbolAnnotations()];
    }

method = '' is not a valid default value

either default value should be null or if statement should be !empty($methodName).
Throwing

PHP ReflectionException:  Method MyTest::() does not exist in phar:///tmp/phpunit-9.5.phar/phpunit/Util/Annotation/Registry.php on line 70

is not a valid workflow.

Please reopen.
Thanks a lot in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

4 participants