Skip to content

Commit

Permalink
Merge pull request #5 from divineniiquaye/analysis-0gWmwE
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
divineniiquaye authored May 17, 2020
2 parents a9ad0d8 + 0c3f228 commit 3cf7c6c
Show file tree
Hide file tree
Showing 46 changed files with 535 additions and 489 deletions.
58 changes: 29 additions & 29 deletions Tests/DefaultRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class DefaultRouterTest extends RouterIntegrationTest
{
public function getRouter(): RouterInterface
{
return new DefaultFlightRouter([new SimpleRouteCompiler, 'compile']);
return new DefaultFlightRouter([new SimpleRouteCompiler(), 'compile']);
}

public function psrServerResponseFactory(): array
{
return [GuzzleHttpPsr7Factory::fromGlobalRequest(), new GuzzleHttpPsr7Factory];
return [GuzzleHttpPsr7Factory::fromGlobalRequest(), new GuzzleHttpPsr7Factory()];
}

public function implicitRoutesAndRequests() : Generator
public function implicitRoutesAndRequests(): Generator
{
yield 'Root Route Text: get, callable' => [
'/',
Expand All @@ -48,7 +48,7 @@ function () {
return 'Hello World';
},
[],
['content-type' => 'text/plain; charset=utf-8']
['content-type' => 'text/plain; charset=utf-8'],
];
yield 'Root Route Html: get, callable' => [
'/',
Expand All @@ -58,7 +58,7 @@ function () {
return '<html><body><h1>Hello World</h1></body></html>';
},
[],
['content-type' => 'text/html; charset=utf-8']
['content-type' => 'text/html; charset=utf-8'],
];
yield 'Root Route XML: get, callable' => [
'/',
Expand All @@ -68,7 +68,7 @@ function () {
return '<?xml version="1.0" encoding="UTF-8"?><route>Hello World</route>';
},
[],
['content-type' => 'application/xml; charset=utf-8']
['content-type' => 'application/xml; charset=utf-8'],
];
yield 'Root Route JSON: get, callable' => [
'/',
Expand All @@ -78,13 +78,13 @@ function () {
return new Helpers\DumpArrayTest();
},
[],
['content-type' => 'application/json']
['content-type' => 'application/json'],
];
yield 'Route Controller: post, nullable' => [
'/test*<Flight\Routing\Tests\Fixtures\SampleController@homePageRequestResponse>',
'/test',
HttpMethods::METHOD_POST,
null
null,
];
yield 'Basic Route: get, callable' => [
'/test',
Expand All @@ -102,45 +102,45 @@ function () {
return 'Hello, this is a basic test route';
},
[],
['status' => 302]
['status' => 302],
];
yield 'Paramter Route: get, callable' => [
'/test/{home}',
'/test/cool',
HttpMethods::METHOD_GET,
function (string $home) {
return 'Hello, this is a basic test route on subpage ' . $home;
return 'Hello, this is a basic test route on subpage '.$home;
},
];
yield 'Paramter & Default Route: get, callable' => [
'/test/{home}',
'/test/cool',
HttpMethods::METHOD_GET,
function (string $home, int $id) {
return $home . $id;
return $home.$id;
},
['defaults' => ['id' => 233]],
['body' => 'cool233']
['body' => 'cool233'],
];
yield 'Optional Paramter Route: get, callable' => [
'/test[/{home}]',
'/test',
HttpMethods::METHOD_GET,
function (?string $home) {
return 'Hello, this is a basic test route on subpage ' . $home;
return 'Hello, this is a basic test route on subpage '.$home;
},
[],
['body' => 'Hello, this is a basic test route on subpage ']
['body' => 'Hello, this is a basic test route on subpage '],
];
yield 'Optional Paramter Route: path, get, callable' => [
'/test[/{home}]',
'/test/cool',
HttpMethods::METHOD_GET,
function (?string $home) {
return 'Hello, this is a basic test route on subpage ' . $home;
return 'Hello, this is a basic test route on subpage '.$home;
},
[],
['body' => 'Hello, this is a basic test route on subpage cool']
['body' => 'Hello, this is a basic test route on subpage cool'],
];
yield 'Route Domain: get, callable' => [
'//example.com/test',
Expand All @@ -149,7 +149,7 @@ function (?string $home) {
function () {
return 'Hello World';
},
['domain' => 'example.com']
['domain' => 'example.com'],
];
yield 'Route Domain Regex: get, callable' => [
'//{id:int}.example.com/test',
Expand All @@ -158,7 +158,7 @@ function () {
function () {
return 'Hello World';
},
['domain' => '99.example.com']
['domain' => '99.example.com'],
];
yield 'Nested Optional Paramter Route 1: get, callable' => [
'/[{action}/[{id}]]',
Expand All @@ -168,7 +168,7 @@ function (?string $action) {
return $action;
},
[],
['status' => 302]
['status' => 302],
];
yield 'Nested Optional Paramter Route 2: get, callable' => [
'/[{action}/[{id}]]',
Expand All @@ -178,7 +178,7 @@ function (?string $action) {
return $action;
},
[],
['status' => 200]
['status' => 200],
];
yield 'Regex Paramter Route : get, callable' => [
'/user/{id:[0-9-]+}',
Expand All @@ -194,45 +194,45 @@ function (int $id) {
HttpMethods::METHOD_GET,
function (?string $lang) {
return $lang;
}
},
];
yield 'Complex Paramter Route 2: get, callable' => [
'/[{lang:[a-z]{2}}/]{name}',
'/en/download',
HttpMethods::METHOD_GET,
function (?string $lang, string $name) {
return $lang . $name;
}
return $lang.$name;
},
];
yield 'Complex Paramter Route 3: get, callable' => [
'[{lang:[a-z]{2}}[-{sublang}]/]{name}[/page-{page=<0>}]',
'/download',
HttpMethods::METHOD_GET,
function (?string $lang, ?string $sublang, string $name, $page) {
return $lang . '-' . $sublang . $name . $page;
return $lang.'-'.$sublang.$name.$page;
},
[],
['body' => '-download0']
['body' => '-download0'],
];
yield 'Complex Paramter Route 4: get, callable' => [
'[{lang:[a-z]{2}}[-{sublang}]/]{name}[/page-{page=<0>}]',
'/en-us/download',
HttpMethods::METHOD_GET,
function (?string $lang, ?string $sublang, string $name, $page) {
return $lang . '-' . $sublang . $name . $page;
return $lang.'-'.$sublang.$name.$page;
},
[],
['body' => 'en-usdownload0']
['body' => 'en-usdownload0'],
];
yield 'Complex Paramter Route 5: get, callable' => [
'[{lang:[a-z]{2}}[-{sublang}]/]{name}[/page-{page=<0>}]',
'/en-us/download/page-12',
HttpMethods::METHOD_GET,
function (?string $lang, ?string $sublang, string $name, $page) {
return $lang . '-' . $sublang . $name . $page;
return $lang.'-'.$sublang.$name.$page;
},
[],
['body' => 'en-usdownload12']
['body' => 'en-usdownload12'],
];
}
}
6 changes: 4 additions & 2 deletions Tests/Fixtures/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Class SampleController
* Class SampleController.
*/
class SampleController
{
Expand All @@ -37,6 +37,7 @@ public function homePageString(): string

/**
* @param ServerRequestInterface $request
*
* @return string
*/
public function homePageRequestString(ServerRequestInterface $request): string
Expand All @@ -46,6 +47,7 @@ public function homePageRequestString(ServerRequestInterface $request): string

/**
* @param ResponseInterface $response
*
* @return ResponseInterface
*/
public function homePageResponse(ResponseInterface $response): ResponseInterface
Expand All @@ -57,7 +59,7 @@ public function homePageResponse(ResponseInterface $response): ResponseInterface

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param ResponseInterface $response
*
* @return ResponseInterface
*/
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/SampleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Psr\Http\Server\RequestHandlerInterface;

/**
* Class SampleMiddleware
* Class SampleMiddleware.
*/
class SampleMiddleware implements MiddlewareInterface
{
Expand All @@ -52,7 +52,7 @@ public function __construct(string $content = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/StopperMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Psr\Http\Server\RequestHandlerInterface;

/**
* Class StopperMiddleware
* Class StopperMiddleware.
*/
class StopperMiddleware implements MiddlewareInterface
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct(ResponseFactoryInterface $responseHandler, string $c
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
26 changes: 12 additions & 14 deletions Tests/RouterIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Flight\Routing\Tests\Fixtures\SampleController;
use Flight\Routing\Tests\Fixtures\SampleMiddleware;
use Generator;
use function implode;
use Laminas\Stratigility\Next;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
Expand All @@ -44,8 +45,6 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function implode;

/**
* Base class for testing adapter integrations.
*
Expand All @@ -57,7 +56,7 @@
*/
abstract class RouterIntegrationTest extends TestCase
{
abstract public function getRouter() : RouterInterface;
abstract public function getRouter(): RouterInterface;

abstract public function psrServerResponseFactory(): array;

Expand All @@ -68,14 +67,14 @@ public function getRouteCollection(ContainerInterface $container = null): RouteC
return new RouteCollector($serverRequest, $responseFactory, $this->getRouter(), null, $container);
}

public function createInvalidResponseFactory() : callable
public function createInvalidResponseFactory(): callable
{
return function () {
Assert::fail('Response generated when it should not have been');
};
}

public function method() : Generator
public function method(): Generator
{
yield 'HEAD: head, post' => [
HttpMethods::METHOD_HEAD,
Expand Down Expand Up @@ -126,7 +125,7 @@ public function testExplicitRequest(string $method, array $routes)
$router = $this->getRouteCollection();
[$serverRequest, $responseFactory] = $this->psrServerResponseFactory();

$finalResponse = (new $responseFactory)->createResponse();
$finalResponse = (new $responseFactory())->createResponse();
$finalResponse = $finalResponse->withHeader('foo-bar', 'baz');
$finalResponse->getBody()->write('FOO BAR BODY');

Expand Down Expand Up @@ -252,7 +251,7 @@ public function testWithoutImplicitMiddleware(string $requestMethod, array $allo
* header => {header}
* ]
*/
abstract public function implicitRoutesAndRequests() : Generator;
abstract public function implicitRoutesAndRequests(): Generator;

/**
* @dataProvider implicitRoutesAndRequests
Expand All @@ -262,7 +261,7 @@ public function testWithImplicitMiddleware(string $routePath, string $requestPat
$router = $this->getRouteCollection();
[$serverRequest, $responseFactory] = $this->psrServerResponseFactory();

$finalResponse = (new $responseFactory)->createResponse();
$finalResponse = (new $responseFactory())->createResponse();
$finalResponse = $finalResponse->withHeader('foo-bar', 'baz');

$middleware = $this->prophesize(MiddlewareInterface::class);
Expand Down Expand Up @@ -342,20 +341,19 @@ public function testWithImplicitRouteMatch(string $routePath, string $requestPat
$this->assertInstanceOf(RouteInterface::class, $router->currentRoute());
}


public function testWithImplicitRouteGroup()
{
$router = $this->getRouteCollection();
[$serverRequest,] = $this->psrServerResponseFactory();
$path = $serverRequest->getUri()->withPath('/group/test');

$router->group([
RouteGroupInterface::NAME => 'group',
RouteGroupInterface::PREFIX => 'group',
RouteGroupInterface::NAME => 'group',
RouteGroupInterface::PREFIX => 'group',
RouteGroupInterface::REQUIREMENTS => [],
RouteGroupInterface::DEFAULTS => ['how' => 'What to do?'],
RouteGroupInterface::MIDDLEWARES => [SampleMiddleware::class],
RouteGroupInterface::SCHEMES => null,
RouteGroupInterface::DEFAULTS => ['how' => 'What to do?'],
RouteGroupInterface::MIDDLEWARES => [SampleMiddleware::class],
RouteGroupInterface::SCHEMES => null,
], function (RouterProxyInterface $route): void {
$route->get('/test*<homePageRequestString>', SampleController::class)->setName('_hello');
});
Expand Down
6 changes: 3 additions & 3 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

$paths = [
dirname(__DIR__, 4) . '/storage/dev-autoload.php',
dirname(__DIR__, 3) . '/autoload.php',
dirname(__DIR__) . '/vendor/autoload.php',
dirname(__DIR__, 4).'/storage/dev-autoload.php',
dirname(__DIR__, 3).'/autoload.php',
dirname(__DIR__).'/vendor/autoload.php',
];

return require current(array_filter($paths, 'file_exists'));
Loading

0 comments on commit 3cf7c6c

Please sign in to comment.