public function testMatchReturnsSuccessfulMatch() { /** @var RequestInterface $request */ $request = self::createMock(RequestInterface::class); $this->matcher->expects(self::once())->method('match')->willReturn($matchResult = new MatchResult(true)); $this->chain->add($this->matcher); $this->chain->add($this->matcher); $result = $this->chain->match($request); self::assertSame($matchResult, $result); }
public function testUnmatchedRequestReturnsResponseIfCallableNotProvided() { $matchResult = new MatchResult(false); /** @var RequestInterface $request */ $request = self::createMock(RequestInterface::class); /** @var ResponseInterface $response */ $response = self::createMock(ResponseInterface::class); $this->matcher->expects(self::any())->method('match')->willReturn($matchResult); $result = $this->middleware->__invoke($request, $response); self::assertEquals($response, $result); }
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = null) { $match = $this->matcher->match($request); if ($match->isMatched()) { $this->dispatcher->dispatch($match->getEvent()->getName(), $match->getEvent()); return $response->withStatus(200, 'push notification has been accepted'); } if (!$next) { return $response; } return $next($request, $response); }