Skip to content

Commit

Permalink
Merge branch 'qa/cs-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Apr 24, 2020
2 parents 4ceaf33 + 1c19d23 commit 069f2b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/AuthenticationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$user = $this->auth->authenticate($request);
if (null !== $user) {
return $handler->handle($request->withAttribute(UserInterface::class, $user)->withAttribute(\Zend\Expressive\Authentication\UserInterface::class, $user));
return $handler->handle(
$request
->withAttribute(UserInterface::class, $user)
->withAttribute(\Zend\Expressive\Authentication\UserInterface::class, $user)
);
}
return $this->auth->unauthorizedResponse($request);
}
Expand Down
20 changes: 12 additions & 8 deletions test/AuthenticationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ public function testProcessWithAuthenticatedUser()
{
$response = $this->prophesize(ResponseInterface::class);

$this->request->withAttribute(UserInterface::class, $this->authenticatedUser->reveal())
->willReturn($this->request->reveal());
$this->request->withAttribute(\Zend\Expressive\Authentication\UserInterface::class, $this->authenticatedUser->reveal())
->willReturn($this->request->reveal());
$this->authentication->authenticate($this->request->reveal())
->willReturn($this->authenticatedUser->reveal());
$this->handler->handle($this->request->reveal())
->willReturn($response->reveal());
$this->request
->withAttribute(UserInterface::class, $this->authenticatedUser->reveal())
->willReturn($this->request->reveal());
$this->request
->withAttribute(\Zend\Expressive\Authentication\UserInterface::class, $this->authenticatedUser->reveal())
->willReturn($this->request->reveal());
$this->authentication
->authenticate($this->request->reveal())
->willReturn($this->authenticatedUser->reveal());
$this->handler
->handle($this->request->reveal())
->willReturn($response->reveal());

$middleware = new AuthenticationMiddleware($this->authentication->reveal());
$result = $middleware->process($this->request->reveal(), $this->handler->reveal());
Expand Down

0 comments on commit 069f2b8

Please sign in to comment.