{"record":{"id":"604f1683e013cb79","repo":"sebastianbergmann/phpunit","slug":"event-class-s-does-not-exist","errorCode":null,"errorMessage":"Event class \"%s\" does not exist","messagePattern":"Event class \"(.+?)\" does not exist","errorType":"exception","errorClass":"UnknownEventException","httpStatus":null,"severity":"error","filePath":"src/Event/TypeMap.php","lineNumber":114,"sourceCode":"        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(\n                    'Event class \"%s\" does not exist',\n                    $eventClass,\n                ),\n            );\n        }\n    }\n\n    /**\n     * @param class-string $subscriberInterface\n     *\n     * @throws InvalidSubscriberException\n     */\n    private function ensureSubscriberInterfaceExtendsInterface(string $subscriberInterface): void\n    {\n        if (!in_array(Subscriber::class, class_implements($subscriberInterface), true)) {\n            throw new InvalidSubscriberException(\n                sprintf(","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Event/TypeMap.php#L96-L132","documentation":"The second argument of TypeMap::addMapping() must be an existing class name; ensureEventClassExists() throws UnknownEventException when class_exists() fails (including its autoload attempt). It runs before the Event-interface check, so a missing class is reported distinctly from a class that exists but does not implement Event.","triggerScenarios":"addMapping(MySubscriberInterface::class, 'App\\Event\\ThingHappened') where ThingHappened is misspelled, not yet created, or defined in a package that is not installed; case mismatches in namespace segments on case-sensitive filesystems.","commonSituations":"Custom event development where the mapping is wired before the event class is written; refactors that rename event classes without updating registration code; partial vendor trees after a failed 'composer install'; stale opcache after moving files.","solutions":["Create the event class or fix the FQCN; prefer MyEvent::class over string literals so the IDE and PHP verify it.","Verify with class_exists(MyEvent::class) in the same process/autoloader context if unsure.","Run 'composer dump-autoload' (or install the missing package) and retry."],"exampleFix":"// before\n$typeMap->addMapping(MySubscriberInterface::class, 'App\\Event\\OrderPlaced'); // literal, class in App\\Events\\\n\n// after\nuse App\\Events\\OrderPlaced;\n\n$typeMap->addMapping(MySubscriberInterface::class, OrderPlaced::class);","handlingStrategy":"validation","validationCode":"if (!class_exists($eventClass)) {\n    throw new InvalidArgumentException($eventClass . ' does not exist; create the class or fix the FQCN');\n}\n\n$typeMap->addMapping($subscriberInterface, $eventClass);","typeGuard":"/** @phpstan-assert class-string $name */\nfunction assertClassExists(string $name): void\n{\n    if (!class_exists($name)) {\n        throw new InvalidArgumentException(\"Class '{$name}' does not exist\");\n    }\n}","tryCatchPattern":null,"preventionTips":["Use MyEvent::class instead of string literals for event class arguments.","Create the event class before wiring its mapping.","Verify autoloading in the same process context when registration is dynamic."],"tags":["phpunit","type-map","class-not-found","autoload","php"],"backgroundTag":"class-not-found","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}