{"record":{"id":"dd31041c2930195e","repo":"sebastianbergmann/phpunit","slug":"interface-s-does-not-exist","errorCode":null,"errorMessage":"Interface \"%s\" does not exist","messagePattern":"Interface \"(.+?)\" does not exist","errorType":"exception","errorClass":"UnknownInterfaceException","httpStatus":null,"severity":"error","filePath":"src/Framework/MockObject/Generator/Generator.php","lineNumber":149,"sourceCode":"\n        return $object;\n    }\n\n    /**\n     * @param list<class-string> $interfaces\n     *\n     * @throws RuntimeException\n     * @throws UnknownInterfaceException\n     */\n    public function testDoubleForInterfaceIntersection(array $interfaces, bool $mockObject, bool $returnValueGeneration = true): MockObject|Stub\n    {\n        if (count($interfaces) < 2) {\n            throw new RuntimeException('At least two interfaces must be specified');\n        }\n\n        foreach ($interfaces as $interface) {\n            if (!interface_exists($interface)) {\n                throw new UnknownInterfaceException($interface);\n            }\n        }\n\n        sort($interfaces);\n\n        $methods = [];\n\n        foreach ($interfaces as $interface) {\n            $methods = array_merge($methods, $this->namesOfMethodsIn($interface));\n        }\n\n        if (count(array_unique($methods)) < count($methods)) {\n            throw new RuntimeException('Interfaces must not declare the same method');\n        }\n\n        $unqualifiedNames = [];\n\n        foreach ($interfaces as $interface) {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/MockObject/Generator/Generator.php#L131-L167","documentation":"While generating an intersection test double, PHPUnit verifies every entry in the interface list with interface_exists(). Any entry that names an existing CLASS (not interface), a misspelled/nonexistent name, or a not-yet-loaded interface triggers this UnknownInterfaceException.","triggerScenarios":"createMockForIntersectionOfInterfaces([A::class, B::class]) where B::class is a class or trait rather than an interface, or a string like 'Psr\\Log\\LoggerAwareInterfce' (typo), or an interface from a package whose autoloader is not available in the test runtime.","commonSituations":"Accidentally including a concrete class (e.g. a repository class instead of its interface) in the intersection list; missing use imports; renamed interfaces after a dependency major-version upgrade (e.g. PSR or Doctrine BC breaks) where the old interface name no longer exists.","solutions":["Use real interface names — check each entry with interface_exists(); replace any class entry with the interface you actually want to double","Fix typos/imports; prefer A::class constants so the IDE and compiler resolve them","composer dump-autoload / install the dependency that ships the interface"],"exampleFix":"// before\n$db = $this->createMockForIntersectionOfInterfaces(\n    [UserRepository::class, LoggerInterface::class] // UserRepository is a class\n);\n\n// after\n$db = $this->createMockForIntersectionOfInterfaces(\n    [UserRepositoryInterface::class, LoggerInterface::class]\n);","handlingStrategy":"validation","validationCode":"foreach ($interfaces as $i => $name) {\n    if (!interface_exists($name)) {\n        throw new InvalidArgumentException(\"#$i is not an interface: $name\");\n    }\n}\n$double = $this->createMockForIntersectionOfInterfaces($interfaces);","typeGuard":"function allAreInterfaces(array $names): bool\n{\n    foreach ($names as $n) {\n        if (!interface_exists($n)) {\n            return false;\n        }\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Reference interfaces with Iface::class constants so names are compiler-checked","Watch for major-version dependency upgrades that rename PSR/framework interfaces"],"tags":["php","phpunit","mockbuilder","interface-not-found","interface-intersection"],"backgroundTag":"class-not-found","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}