/**
  * @test
  */
 public function it_dispatches_the_command()
 {
     $commandName = 'stdClass';
     $payload = ['user_id' => 123];
     $commandBus = $this->prophesize(CommandBus::class);
     $commandBus->dispatch(Argument::type(Message::class))->shouldBeCalled();
     $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)->shouldBeCalled();
     $response = $this->prophesize(ResponseInterface::class);
     $response->withStatus(Middleware::STATUS_CODE_ACCEPTED)->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::callableShouldNotBeCalledWithException($this));
 }
 /**
  * @test
  */
 public function it_dispatches_the_query_with_post_data()
 {
     $queryName = 'stdClass';
     $parsedBody = ['filter' => []];
     $payload = ['user_id' => 123];
     $queryBus = $this->prophesize(QueryBus::class);
     $queryBus->dispatch(Argument::type(Message::class))->shouldBeCalled()->willReturn($this->prophesize(Promise::class)->reveal());
     $message = $this->prophesize(Message::class);
     $messageFactory = $this->prophesize(MessageFactory::class);
     $messageFactory->createMessageFromArray($queryName, ['payload' => array_merge($payload, ['data' => $parsedBody]), 'metadata' => []])->willReturn($message->reveal())->shouldBeCalled();
     $responseStrategy = $this->prophesize(ResponseStrategy::class);
     $responseStrategy->fromPromise(Argument::type(Promise::class))->shouldBeCalled();
     $request = $this->prophesize(ServerRequestInterface::class);
     $request->getMethod()->willReturn('POST')->shouldBeCalled();
     $request->getParsedBody()->willReturn($parsedBody)->shouldBeCalled();
     $request->getQueryParams()->willReturn($payload)->shouldBeCalled();
     $request->getAttribute(QueryMiddleware::NAME_ATTRIBUTE)->willReturn($queryName)->shouldBeCalled();
     $response = $this->prophesize(ResponseInterface::class);
     $response->withStatus(Argument::type('integer'))->shouldNotBeCalled();
     $gatherer = $this->prophesize(MetadataGatherer::class);
     $gatherer->getFromRequest($request)->shouldBeCalled();
     $middleware = new QueryMiddleware($queryBus->reveal(), $messageFactory->reveal(), $responseStrategy->reveal(), $gatherer->reveal());
     $middleware($request->reveal(), $response->reveal(), Helper::callableShouldNotBeCalledWithException($this));
 }