Skip to content

Commit

Permalink
Adding missing coverage statements in tests.
Browse files Browse the repository at this point in the history
Updating return types in Application to match method declaration.
Cleaning up Router::mergeGroupConfigs.
  • Loading branch information
Brent Scheffler committed Aug 30, 2019
1 parent 4109e02 commit 62fdd8e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ public function dispatch(ServerRequestInterface $request): ResponseInterface
/**
* Compile a middleware stack.
*
* @param array<MiddlewareInterface>
* @param array<MiddlewareInterface> $middleware
* @param RequestHandlerInterface $kernel
* @return RequestHandlerInterface
*/
private function compileMiddleware(array $middleware, RequestHandlerInterface $kernel): RequestHandler
private function compileMiddleware(array $middleware, RequestHandlerInterface $kernel): RequestHandlerInterface
{
$middleware = \array_reverse($middleware);

return \array_reduce($middleware, function(RequestHandlerInterface $handler, MiddlewareInterface $middleware) {
return \array_reduce($middleware, function(RequestHandlerInterface $handler, MiddlewareInterface $middleware): RequestHandler {

return new RequestHandler(function(ServerRequestInterface $request) use ($handler, $middleware): ResponseInterface {

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/MethodNotAllowedHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class MethodNotAllowedHttpException extends HttpException
public function __construct(array $methodsAllowed, ?string $message = null, ?int $code = null, ?Exception $previous = null)
{
$this->headers['Allow'] = \implode(", ", $methodsAllowed);
parent::__construct($message, $code, $previous);
parent::__construct($message ?? "Method not allowed", $code ?? $this->httpStatus, $previous);
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/ServiceUnavailableHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class ServiceUnavailableHttpException extends HttpException
public function __construct(string $retryAfter, ?string $message = null, ?int $code = null, ?Exception $previous = null)
{
$this->headers["Retry-After"] = $retryAfter;
parent::__construct($message, $code, $previous);
parent::__construct($message ?? "Service unavailable", $code ?? $this->httpStatus, $previous);
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/TooManyRequestsHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class TooManyRequestsHttpException extends HttpException
public function __construct(string $retryAfter, ?string $message = null, ?int $code = null, ?Exception $previous = null)
{
$this->headers["Retry-After"] = $retryAfter;
parent::__construct($message, $code, $previous);
parent::__construct($message ?? "Too many requests", $code ?? $this->httpStatus, $previous);
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/UnauthorizedHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class UnauthorizedHttpException extends HttpException
public function __construct(string $authMethod, ?string $message = null, ?int $code = null, ?Exception $previous = null)
{
$this->headers["WWW-Authenticate"] = $authMethod;
parent::__construct($message, $code, $previous);
parent::__construct($message ?? "Unauthorized", $code ?? $this->httpStatus, $previous);
}
}
22 changes: 11 additions & 11 deletions src/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function options(string $path, $action): Route
/**
* Group routes together with a set of shared configuration options.
*
* @param array $config
* @param array $groupConfig
* @param \closure $callback
* @return void
*/
Expand Down Expand Up @@ -251,15 +251,15 @@ public function group(array $groupConfig, \closure $callback): void
*/
protected function mergeGroupConfig(array $config, array $groupConfig): array
{
$mergedConfig['scheme'] = $groupConfig['scheme'] ?? $config['scheme'] ?? null;
$mergedConfig['hostname'] = $groupConfig['hostname'] ?? $config['hostname'] ?? null;
$mergedConfig['prefix'] = $groupConfig['prefix'] ?? $config['pregix'] ?? null;
$mergedConfig['namespace'] = $groupConfig['namespace'] ?? $config['namespace'] ?? null;
$mergedConfig['middleware'] = \array_merge(
$config['middleware'] ?? [],
$groupConfig['middleware'] ?? []
);

return $mergedConfig;
return [
'scheme'=> $groupConfig['scheme'] ?? $config['scheme'] ?? null,
'hostname' => $groupConfig['hostname'] ?? $config['hostname'] ?? null,
'prefix' => $groupConfig['prefix'] ?? $config['pregix'] ?? null,
'namespace' => $groupConfig['namespace'] ?? $config['namespace'] ?? null,
'middleware' => \array_merge(
$config['middleware'] ?? [],
$groupConfig['middleware'] ?? []
)
];
}
}
2 changes: 2 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public function test_dispatch_with_resolvable_route()
$this->assertEquals("OK", $response->getBody()->getContents());
}



public function test_send()
{
$application = new Application(new Router);
Expand Down
1 change: 1 addition & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @covers Limber\Router\Route
* @covers Limber\Router\Router
* @covers ::class_method
*/
class RouteTest extends TestCase
Expand Down

0 comments on commit 62fdd8e

Please sign in to comment.