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

Class "PHPUnit\Metadata\Api\DataProvider" not found #5477

Closed
crowne opened this issue Aug 18, 2023 · 4 comments
Closed

Class "PHPUnit\Metadata\Api\DataProvider" not found #5477

crowne opened this issue Aug 18, 2023 · 4 comments
Labels
type/bug Something is broken version/9 Something affects PHPUnit 9 version/10 Something affects PHPUnit 10

Comments

@crowne
Copy link

crowne commented Aug 18, 2023

Q A
PHPUnit version 10.3.2
PHP version 8.2.7
Installation Method Composer

Summary

Error when running tests
PHP Unit Class "PHPUnit\Metadata\Api\DataProvider" not found

Current behavior

composer-docker-image-shell:/app# app/vendor/bin/phpunit test/unit


An error occurred inside PHPUnit.

Message:  Class "PHPUnit\Metadata\Api\DataProvider" not found
Location: /app/app/vendor/phpunit/phpunit/src/Framework/TestBuilder.php:38

#0 /app/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(477): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testLocateTestF...')
#1 /app/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(125): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#2 /app/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(215): PHPUnit\Framework\TestSuite::fromClassReflector(Object(ReflectionClass))
#3 /app/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(243): PHPUnit\Framework\TestSuite->addTestSuite(Object(ReflectionClass))
#4 /app/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(261): PHPUnit\Framework\TestSuite->addTestFile('/app/test/unit/...')
#5 /app/app/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(83): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#6 /app/app/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(47): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath('/app/test/unit', Array)
#7 /app/app/vendor/phpunit/phpunit/src/TextUI/Application.php(356): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build(Object(PHPUnit\TextUI\Configuration\Configuration)) 
#8 /app/app/vendor/phpunit/phpunit/src/TextUI/Application.php(103): PHPUnit\TextUI\Application->buildTestSuite(Object(PHPUnit\TextUI\Configuration\Configuration))
#9 /app/app/vendor/phpunit/phpunit/phpunit(99): PHPUnit\TextUI\Application->run(Array)
#10 /app/app/vendor/bin/phpunit(122): include('/app/app/vendor...')
#11 {main}

How to reproduce

See this issue on stackoverflow
https://stackoverflow.com/questions/76484539/php-unit-class-phpunit-metadata-api-dataprovider-not-found-with-repro-case

Expected behavior

Expect tests to run as they do if the phpunit version is downgraded to 10.0.1

@crowne crowne added type/bug Something is broken version/10 Something affects PHPUnit 10 version/9 Something affects PHPUnit 9 labels Aug 18, 2023
@mihaibalalau
Copy link

It seems to be a namespace error. I did this in my composer.json as a workaround:

"autoload-dev": {
        "psr-4": {
            "PHPUnit\\Metadata\\": "vendor/phpunit/phpunit/src/Metadata",
            "PHPUnit\\Metadata\\Annotation\\Parser\\": "vendor/phpunit/phpunit/src/Metadata/Parser/Annotation"
        }
    }

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Aug 19, 2023

PHPUnit uses classmap-based autoloading, you must not mess with that.

@crowne
Copy link
Author

crowne commented Aug 19, 2023

Thanks for your replies, I've used the work-around from @mihaibalalau
Unfortunately the codebase to which I'm applying this is quite cluttered
and adding a classmap-based autoloader increases the runtime of all the composer scripts by more than 60 seconds.

So there's clearly still a lof of refactoring to be done, thanks for your help with step-1 ... adding unit tests

@zippex
Copy link

zippex commented Sep 4, 2023

It seems to be a namespace error. I did this in my composer.json as a workaround:

"autoload-dev": {
        "psr-4": {
            "PHPUnit\\Metadata\\": "vendor/phpunit/phpunit/src/Metadata",
            "PHPUnit\\Metadata\\Annotation\\Parser\\": "vendor/phpunit/phpunit/src/Metadata/Parser/Annotation"
        }
    }

I can confirm the behaviour. In my vendor/composer/ directory, these classes were indeed missing in the autoload files, despite multiple composer dump-autoload and even deleting the whole vendor folder and reinstalling it 🤯

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

No branches or pull requests

4 participants