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

Subscriber "PHPUnit\Event\Test\DataProviderMethodCalledSubscriber" does not exist or is not an interface #5570

Closed
nishant04412 opened this issue Nov 20, 2023 · 5 comments
Labels
type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@nishant04412
Copy link

nishant04412 commented Nov 20, 2023

Q A
PHPUnit version 10
PHP version 8.1
Installation Method Composer

Summary

After upgrading from phpunit/phpunit": "^9.5" to phpunit/phpunit": "^10.0" and running command vendor/bin/phpunit getting error as below:

An error occurred inside PHPUnit.

Message:  Subscriber "PHPUnit\Event\Test\DataProviderMethodCalledSubscriber" does not exist or is not an interface
Location: /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/TypeMap.php:97

#0 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/TypeMap.php(42): PHPUnit\Event\TypeMap->ensureSubscriberInterfaceExists('PHPUnit\\Event\\T...')
#1 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(252): PHPUnit\Event\TypeMap->addMapping('PHPUnit\\Event\\T...', 'PHPUnit\\Event\\T...')
#2 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(162): PHPUnit\Event\Facade->registerDefaultTypes(Object(PHPUnit\Event\TypeMap))
#3 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(150): PHPUnit\Event\Facade->typeMap()
#4 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(132): PHPUnit\Event\Facade->deferredDispatcher()
#5 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(45): PHPUnit\Event\Facade->createDispatchingEmitter()
#6 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(32): PHPUnit\Event\Facade->__construct()
#7 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/Event/Facade.php(40): PHPUnit\Event\Facade::instance()
#8 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/src/TextUI/Application.php(86): PHPUnit\Event\Facade::emitter()
#9 /opt/homebrew/var/www/mag2ce/vendor/phpunit/phpunit/phpunit(99): PHPUnit\TextUI\Application->run(Array)
#10 {main}

I saw multiple issues closed with same error like #5408 and #5417 but skeptical if issue is related to multiple phpunit version mixup or some newly introduced changes.

Additional Analysis

As per my current analysis, I am getting error when upgrading from phpunit 9 to 10 and my composer.json file contains autoload section as below:

"autoload": {
        "exclude-from-classmap": [
            "**/Test/**"
        ]
    },

But when I remove **/Test/** from above block, command works fine. Looks like phpunit/phpunit/src/Event/TypeMap.php is missing some of required classes when performing mapping.

Note: Adding **/Test/** is important from performance's perspective so removing it might not be best idea.

It would be great if someone can help with this or provide some more info if this is indeed related to multiple phpunit versions mixup.

@nishant04412 nishant04412 added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Nov 20, 2023
@sebastianbergmann
Copy link
Owner

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.

@nishant04412
Copy link
Author

@sebastianbergmann Thank you for quick reply. Yes I tried to debug based on this input but couldn't find anything.

Here is what I did:

  1. I updated phpunit version in my composer.json
  2. I ran composer update command which got successfully executed (It would have caused error if there was any dependency related issue)
  3. I ran vendor/bin/phpunit command and got the error.

Also, please check my Additional Analysis of the issue and if it has anything to do with the issue.

@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Nov 20, 2023
@nishant04412
Copy link
Author

Steps to reproduce:

  1. Create composer.json file as below:
{
  "name": "test/new",
  "require": {
    "php": "~8.1.0||~8.2.0"
  },
  "require-dev": {
    "phpunit/phpunit": "^10.0"
  },
  "autoload": {
    "exclude-from-classmap": [
      "**/Test/**"
    ]
  },
  "prefer-stable": true
}
  1. Run composer install
  2. Run vendor/bin/phpunit

@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label Nov 20, 2023
@sebastianbergmann
Copy link
Owner

You are configuring Composer to exclude **/Test/** from the autoloader classmap:

  "autoload": {
    "exclude-from-classmap": [
      "**/Test/**"
    ]
  },

This prevents some of PHPUnit's classes to be found.

I do not consider this to be a bug in PHPUnit but rather an incorrect usage of Composer.

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

2 participants