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

Message: Class "PHPUnit\Metadata\Api\DataProvider" not found #5341

Closed
chaz6chez opened this issue Apr 23, 2023 · 6 comments
Closed

Message: Class "PHPUnit\Metadata\Api\DataProvider" not found #5341

chaz6chez opened this issue Apr 23, 2023 · 6 comments
Labels
type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@chaz6chez
Copy link

chaz6chez commented Apr 23, 2023

Q A
PHPUnit version 10.1.2
PHP version 8.1.18
Installation Method Composer

Summary

The same case can be run on PHPUnit 9.6.

Current behavior

An error occurred inside PHPUnit.

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

#0 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(494): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testSomething')
#1 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(133): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#2 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(232): PHPUnit\Framework\TestSuite::fromClassReflector(Object(ReflectionClass))
#3 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(261): PHPUnit\Framework\TestSuite->addTestSuite(Object(ReflectionClass))
#4 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(278): PHPUnit\Framework\TestSuite->addTestFile('/var/www/tests/...')
#5 /var/www/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(76): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#6 /var/www/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(48): PHPUnit\TextUI\Configuration\TestSuiteBuilder->testSuiteFromPath('/var/www/tests', Array)
#7 /var/www/vendor/phpunit/phpunit/src/TextUI/Application.php(335): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build(Object(PHPUnit\TextUI\Configuration\Configuration))
#8 /var/www/vendor/phpunit/phpunit/src/TextUI/Application.php(102): PHPUnit\TextUI\Application->buildTestSuite(Object(PHPUnit\TextUI\Configuration\Configuration))
#9 /var/www/vendor/phpunit/phpunit/phpunit(99): PHPUnit\TextUI\Application->run(Array)
#10 /var/www/vendor/bin/phpunit(123): include('/var/www/vendor...')
#11 {main}

How to reproduce

case:

<?php declare(strict_types=1);

namespace Workbunny\Tests;

use PHPUnit\Framework\TestCase;

final class CommandsTest extends TestCase
{
    public function testSomething(): void
    {
        $this->fail('ok');
    }
}

composer info:

doctrine/inflector                 2.0.6   PHP Doctrine Inflector is a small library that can perform string manipulation...
illuminate/bus                     v10.8.0 The Illuminate Bus package.
illuminate/collections             v10.8.0 The Illuminate Collections package.
illuminate/conditionable           v10.8.0 The Illuminate Conditionable package.
illuminate/container               v10.8.0 The Illuminate Container package.
illuminate/contracts               v10.8.0 The Illuminate Contracts package.
illuminate/events                  v10.8.0 The Illuminate Events package.
illuminate/macroable               v10.8.0 The Illuminate Macroable package.
illuminate/pipeline                v10.8.0 The Illuminate Pipeline package.
illuminate/redis                   v10.8.0 The Illuminate Redis package.
illuminate/support                 v10.8.0 The Illuminate Support package.
myclabs/deep-copy                  1.11.1  Create deep copies (clones) of your objects
nesbot/carbon                      2.66.0  An API extension for DateTime that supports 281 different languages.
nikic/fast-route                   v1.3.0  Fast request router for PHP
nikic/php-parser                   v4.15.4 A PHP parser written in PHP
phar-io/manifest                   2.0.3   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    3.2.1   Library for handling version information and constraints
phpunit/php-code-coverage          10.1.1  Library that provides collection, processing, and rendering functionality for ...
phpunit/php-file-iterator          4.0.1   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                4.0.0   Invoke callables with a timeout
phpunit/php-text-template          3.0.0   Simple template engine.
phpunit/php-timer                  6.0.0   Utility class for timing
phpunit/phpunit                    10.1.2  The PHP Unit Testing framework.
psr/container                      2.0.2   Common Container Interface (PHP FIG PSR-11)
psr/simple-cache                   3.0.0   Common interfaces for simple caching
sebastian/cli-parser               2.0.0   Library for parsing CLI options
sebastian/code-unit                2.0.0   Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup 3.0.0   Looks up which function or method a line of code belongs to
sebastian/comparator               5.0.0   Provides the functionality to compare PHP values for equality
sebastian/complexity               3.0.0   Library for calculating the complexity of PHP code units
sebastian/diff                     5.0.1   Diff implementation
sebastian/environment              6.0.1   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 5.0.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state             6.0.0   Snapshotting of global state
sebastian/lines-of-code            2.0.0   Library for counting the lines of code in PHP source code
sebastian/object-enumerator        5.0.0   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         3.0.0   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        5.0.0   Provides functionality to recursively process PHP variables
sebastian/type                     4.0.0   Collection of value objects that represent the types of the PHP type system
sebastian/version                  4.0.1   Library that helps with managing the version number of Git-hosted PHP projects
symfony/console                    v6.2.8  Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts      v3.2.1  A generic function and convention to trigger deprecation notices
symfony/polyfill-ctype             v1.27.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme     v1.27.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer   v1.27.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.27.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php80             v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/service-contracts          v3.2.1  Generic abstractions related to writing services
symfony/string                     v6.2.8  Provides an object-oriented API to strings and deals with bytes, UTF-8 code po...
symfony/translation                v6.2.8  Provides tools to internationalize your application
symfony/translation-contracts      v3.2.1  Generic abstractions related to translation
symfony/var-dumper                 v6.2.8  Provides mechanisms for walking through any arbitrary PHP variable
theseer/tokenizer                  1.2.1   A small library for converting tokenized PHP source code into XML and potentia...
voku/portable-ascii                2.0.1   Portable ASCII library - performance optimized (ascii) string functions for php.
webman/console                     v1.2.33 Webman console
workerman/webman-framework         v1.5.5  High performance HTTP Service Framework.
workerman/workerman                v4.1.9  An asynchronous event driven PHP framework for easily building fast, scalable ...

Expected behavior

can run.

@chaz6chez chaz6chez added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Apr 23, 2023
@wol-soft
Copy link

I've also encountered the error (Runtime PHP 8.2.5). Downgrading to 10.1.1 and the tests run again.

@hafiz-abdul-moid
Copy link

I've also encountered the error (Runtime PHP 8.18).

@tomaserlebach
Copy link

Same issue with PHP 8.1.18

@sebastianbergmann
Copy link
Owner

I cannot reproduce this:

$ cat Test.php                               
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

final class Test extends TestCase
{
    public function testOne(): void
    {
        $this->fail('ok');
    }
}
$ /usr/local/src/phpunit/phpunit Test.php
PHPUnit 10.1.2-1-gd40581c495 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.5

F                                                                   1 / 1 (100%)

Time: 00:00.018, Memory: 4.00 MB

There was 1 failure:

1) Test::testOne
ok

/home/sb/Test.php:8

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

It appears that you have different installations of PHPUnit mixed up.

For instance, you may have used Composer to install PHPUnit and have configured the autoloader generated by Composer as PHPUnit's bootstrap script but then you invoke PHPUnit using an executable other than vendor/bin/phpunit.

@klevunin
Copy link

Downgrading helped me too. I used composer

@chaz6chez
Copy link
Author

microsoft/WSL#5074

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/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

6 participants