/**
  * @test
  */
 public function callsNextMiddlewareIfPresentAndDomainPayloadIsDomainPayload()
 {
     $called = false;
     $next = function (ServerRequestInterface $request, ResponseInterface $response, callable $next = null) use(&$called) : ResponseInterface {
         $called = true;
         return $response;
     };
     $request = new ServerRequest();
     $payload = $this->createMock(Payload::class);
     $this->resolvers[0]->expects($this->once())->method('resolve')->will($this->returnValue($this->createSimpleResponder()));
     $request = $request->withAttribute(self::$domainPayloadAttribute, $payload);
     $this->middleware->__invoke($request, new Response(), $next);
     $this->assertTrue($called);
 }
Пример #2
0
 /**
  * @test
  */
 public function beforeExecuteResponderMiddlewareWillBeCalledBeforeResponderExecutorMiddleware()
 {
     $expectedOrder = ['beforeExecuteResponder', 'executeResponder'];
     $order = [];
     $this->actionResolverMiddleware->expects($this->any())->method('__invoke')->will($this->returnCallback($this->createTestMiddleware()));
     $this->actionExecutorMiddleware->expects($this->any())->method('__invoke')->will($this->returnCallback($this->createTestMiddleware()));
     $this->responderResolverMiddleware->expects($this->any())->method('__invoke')->will($this->returnCallback($this->createTestMiddleware()));
     $beforeExecuteResponderMiddleware = $this->createTestMiddleware(function () use(&$order) {
         $order[] = 'beforeExecuteResponder';
     });
     $responderExecutorMiddlewareStub = $this->createTestMiddleware(function () use(&$order) {
         $order[] = 'executeResponder';
     });
     $this->responderExecutorMiddleware->expects($this->any())->method('__invoke')->will($this->returnCallback($responderExecutorMiddlewareStub));
     $middleware = $this->getMockedAdroitMiddleware();
     $middleware->beforeExecuteResponder($beforeExecuteResponderMiddleware);
     $middleware->__invoke($this->request, $this->response);
     $this->assertEquals($order, $expectedOrder);
 }
 /**
  * Creates a new {@link \bitExpert\Adrenaline\Responder\Resolver\NegotiatingResponderResolver}.
  * @param \bitExpert\Adroit\Responder\Resolver\ResponderResolver[] $resolvers
  * @param string $domainPayloadAttribute
  * @param string $responderAttribute
  * @param ContentNegotiationService $negotiationService
  * @throws \InvalidArgumentException
  */
 public function __construct(array $resolvers, $domainPayloadAttribute, $responderAttribute, ContentNegotiationService $negotiationService)
 {
     parent::__construct($resolvers, $domainPayloadAttribute, $responderAttribute);
     $this->negotiationService = $negotiationService;
 }