{"record":{"id":"755fa53466b430cb","repo":"sebastianbergmann/phpunit","slug":"subscriber-s-does-not-exist-or-is-not-an-interf","errorCode":null,"errorMessage":"Subscriber \"%s\" does not exist or is not an interface","messagePattern":"Subscriber \"(.+?)\" does not exist or is not an interface","errorType":"exception","errorClass":"UnknownSubscriberException","httpStatus":null,"severity":"error","filePath":"src/Event/TypeMap.php","lineNumber":97,"sourceCode":"        }\n\n        throw new MapError(\n            sprintf(\n                'Subscriber \"%s\" does not implement a known interface',\n                $subscriber::class,\n            ),\n        );\n    }\n\n    /**\n     * @param class-string $subscriberInterface\n     *\n     * @throws UnknownSubscriberException\n     */\n    private function ensureSubscriberInterfaceExists(string $subscriberInterface): void\n    {\n        if (!interface_exists($subscriberInterface)) {\n            throw new UnknownSubscriberException(\n                sprintf(\n                    'Subscriber \"%s\" does not exist or is not an interface',\n                    $subscriberInterface,\n                ),\n            );\n        }\n    }\n\n    /**\n     * @param class-string $eventClass\n     *\n     * @throws UnknownEventException\n     */\n    private function ensureEventClassExists(string $eventClass): void\n    {\n        if (!class_exists($eventClass)) {\n            throw new UnknownEventException(\n                sprintf(","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Event/TypeMap.php#L79-L115","documentation":"The first argument of TypeMap::addMapping() must name an interface; ensureSubscriberInterfaceExists() runs interface_exists() (which triggers autoload) and throws UnknownSubscriberException when the string is neither a loaded nor autoloadable interface. The distinction matters: the error fires at registration time for a bad FQCN, before any dispatching happens.","triggerScenarios":"addMapping('App\\Test\\MySubscriberInterface', ...) where that name is misspelled, is actually a class rather than an interface, or lives in a file Composer has not mapped; passing a string with stray whitespace or a doubled backslash; referencing an interface renamed between versions.","commonSituations":"Wiring custom event types in extension bootstrap code; forgetting 'composer dump-autoload' after adding a new namespace or changing autoload-dev PSR-4 prefixes; upgrading PHPUnit where subscriber interface namespaces changed while custom mappings kept old FQCNs.","solutions":["Pass the interface name via the ::class constant (MySubscriberInterface::class) instead of a string literal so typos surface as PHP errors.","Run 'composer dump-autoload' and confirm interface_exists('App\\Test\\MySubscriberInterface') returns true in 'php -r'.","If the name refers to a class, convert it to an interface or pass the actual interface the subscribers will implement."],"exampleFix":"// before\n$typeMap->addMapping('App\\Test\\MySubscriberrInterface', MyEvent::class); // typo + literal\n\n// after\nuse App\\Test\\MySubscriberInterface;\n\n$typeMap->addMapping(MySubscriberInterface::class, MyEvent::class);","handlingStrategy":"validation","validationCode":"if (!interface_exists($subscriberInterface)) {\n    throw new InvalidArgumentException($subscriberInterface . ' is not a loadable interface; fix the FQCN or run composer dump-autoload');\n}\n\n$typeMap->addMapping($subscriberInterface, $eventClass);","typeGuard":"/** @phpstan-assert class-string $name */\nfunction assertInterfaceName(string $name): void\n{\n    if (!interface_exists($name)) {\n        throw new InvalidArgumentException(\"Interface '{$name}' does not exist\");\n    }\n}","tryCatchPattern":null,"preventionTips":["Pass interface names via ::class constants, never string literals.","Run composer dump-autoload after adding namespaces or changing PSR-4 mappings.","Re-check custom FQCNs after PHPUnit upgrades."],"tags":["phpunit","type-map","interface-not-found","autoload","php"],"backgroundTag":"class-or-interface-not-found","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}