{"record":{"id":"b0ff732c309a2f55","repo":"sebastianbergmann/phpunit","slug":"at-least-two-interfaces-must-be-specified","errorCode":null,"errorMessage":"At least two interfaces must be specified","messagePattern":"At least two interfaces must be specified","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Framework/MockObject/Generator/Generator.php","lineNumber":144,"sourceCode":"        if ($mockObject) {\n            assert($object instanceof MockObject);\n        } else {\n            assert($object instanceof Stub);\n        }\n\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');","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/MockObject/Generator/Generator.php#L126-L162","documentation":"createMockForIntersectionOfInterfaces()/createStubForIntersectionOfInterfaces() build a test double that satisfies the intersection of several interfaces at once (PHP does not allow runtime intersection types, so PHPUnit generates a named intersection interface). At least two interfaces are required for an intersection to be meaningful; passing fewer causes this RuntimeException.","triggerScenarios":"createMockForIntersectionOfInterfaces([SessionHandlerInterface::class]) with a single element, an empty array, or a list where a dynamic/computed list collapsed to one entry (e.g. array_filter removed the second interface, config returned one).","commonSituations":"Test data built dynamically from configuration or parametrized providers where the second interface is optional and sometimes absent; refactoring from a hand-written combined interface to intersection mocks; copy-paste leftovers where one interface was commented out.","solutions":["Pass at least two existing interfaces: createMockForIntersectionOfInterfaces([A::class, B::class])","If only one interface is needed, use createMock(A::class) instead","When the list is computed, guard it: if (count($interfaces) < 2) { return createMock($interfaces[0]); }"],"exampleFix":"// before\n$registry = $this->createMockForIntersectionOfInterfaces(\n    [CacheInterface::class] // only one\n);\n\n// after\n$registry = $this->createMockForIntersectionOfInterfaces(\n    [CacheInterface::class, LoggerInterface::class]\n);\n// or, if one suffices:\n$registry = $this->createMock(CacheInterface::class);","handlingStrategy":"validation","validationCode":"if (count($interfaces) < 2) {\n    // Not an intersection: fall back to a plain mock\n    $double = $this->createMock($interfaces[0]);\n} else {\n    $double = $this->createMockForIntersectionOfInterfaces($interfaces);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use intersection mocks only when two or more interfaces are genuinely required together","For dynamically built interface lists, assert count >= 2 in a data-provider guard before the test body"],"tags":["php","phpunit","mockbuilder","interface-intersection","createmockforintersectionofinterfaces"],"backgroundTag":"mock-interface-intersection-invalid","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}