getMockBuilder(NotificationHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'handle']) ->getMock(); $handlerA->method('supports')->willReturn(true); $handlerA->expects($this->once())->method('handle'); $handlerB = $this->getMockBuilder(NotificationHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'handle']) ->getMock(); $handlerB->method('supports')->willReturn(false); $handlerB->expects($this->never())->method('handle'); $handlerC = $this->getMockBuilder(NotificationHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'handle']) ->getMock(); $handlerC->method('supports')->willReturn(true); $handlerC->expects($this->once())->method('handle'); $jsonRpc = new JsonRpcHandler(new Factory(), [], [$handlerA, $handlerB, $handlerC], new NullLogger()); $result = $jsonRpc->process( '{"jsonrpc": "2.0", "id": 1, "method": "notifications/foobar"}' ); iterator_to_array($result); } #[TestDox('Make sure a single request can NOT be handled by multiple handlers.')] public function testHandleMultipleRequests(): void { $handlerA = $this->getMockBuilder(RequestHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'createResponse']) ->getMock(); $handlerA->method('supports')->willReturn(true); $handlerA->expects($this->once())->method('createResponse')->willReturn(new Response(1)); $handlerB = $this->getMockBuilder(RequestHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'createResponse']) ->getMock(); $handlerB->method('supports')->willReturn(false); $handlerB->expects($this->never())->method('createResponse'); $handlerC = $this->getMockBuilder(RequestHandlerInterface::class) ->disableOriginalConstructor() ->onlyMethods(['supports', 'createResponse']) ->getMock(); $handlerC->method('supports')->willReturn(true); $handlerC->expects($this->never())->method('createResponse'); $jsonRpc = new JsonRpcHandler(new Factory(), [$handlerA, $handlerB, $handlerC], [], new NullLogger()); $result = $jsonRpc->process( '{"jsonrpc": "2.0", "id": 1, "method": "request/foobar"}' ); iterator_to_array($result); } }