コード例 #1
0
 /**
  * @test
  */
 public function it_calls_next_with_exception_if_dispatch_failed()
 {
     $commandName = 'stdClass';
     $payload = ['user_id' => 123];
     $commandBus = $this->prophesize(CommandBus::class);
     $commandBus->dispatch(Argument::type(Message::class))->shouldBeCalled()->willThrow(new \Exception('Error'));
     $message = $this->prophesize(Message::class);
     $messageFactory = $this->prophesize(MessageFactory::class);
     $messageFactory->createMessageFromArray($commandName, ['payload' => $payload, 'metadata' => []])->willReturn($message->reveal())->shouldBeCalled();
     $request = $this->prophesize(ServerRequestInterface::class);
     $request->getParsedBody()->willReturn($payload)->shouldBeCalled();
     $request->getAttribute(CommandMiddleware::NAME_ATTRIBUTE)->willReturn($commandName);
     $response = $this->prophesize(ResponseInterface::class);
     $response->withStatus(Middleware::STATUS_CODE_INTERNAL_SERVER_ERROR)->shouldBeCalled();
     $gatherer = $this->prophesize(MetadataGatherer::class);
     $gatherer->getFromRequest($request->reveal())->willReturn([])->shouldBeCalled();
     $middleware = new CommandMiddleware($commandBus->reveal(), $messageFactory->reveal(), $gatherer->reveal());
     $middleware($request->reveal(), $response->reveal(), Helper::callableWithExceptionResponse());
 }