Small code cleanup

This commit is contained in:
Timothy Warren 2019-01-07 09:08:00 -05:00
parent 0503cad15f
commit 5d752f6ee3
4 changed files with 20 additions and 29 deletions

View File

@ -45,10 +45,10 @@ final class Dispatcher extends RoutingBase {
protected $matcher; protected $matcher;
/** /**
* Class wrapper for input superglobals * Routing array
* @var \Psr\Http\Message\ServerRequestInterface * @var array
*/ */
protected $request; protected $routes;
/** /**
* Routes added to router * Routes added to router
@ -67,8 +67,7 @@ final class Dispatcher extends RoutingBase {
$router = $this->container->get('aura-router'); $router = $this->container->get('aura-router');
$this->router = $router->getMap(); $this->router = $router->getMap();
$this->matcher = $router->getMatcher(); $this->matcher = $router->getMatcher();
$this->request = $container->get('request'); $this->routes = $this->config->get('routes');
$this->outputRoutes = $this->setupRoutes(); $this->outputRoutes = $this->setupRoutes();
} }

View File

@ -39,10 +39,10 @@ class RoutingBase {
protected $config; protected $config;
/** /**
* Routing array * Class wrapper for input superglobals
* @var array * @var \Psr\Http\Message\ServerRequestInterface
*/ */
protected $routes; protected $request;
/** /**
* Constructor * Constructor
@ -56,7 +56,7 @@ class RoutingBase {
{ {
$this->container = $container; $this->container = $container;
$this->config = $container->get('config'); $this->config = $container->get('config');
$this->routes = $this->config->get('routes'); $this->request = $container->get('request');
} }
/** /**
@ -67,8 +67,7 @@ class RoutingBase {
*/ */
public function path(): string public function path(): string
{ {
$request = $this->container->get('request'); $path = $this->request->getUri()->getPath();
$path = $request->getUri()->getPath();
$cleanedPath = $this->string($path) $cleanedPath = $this->string($path)
->replace('%20', '') ->replace('%20', '')
->trim() ->trim()
@ -116,5 +115,4 @@ class RoutingBase {
$segments = $this->segments(); $segments = $this->segments();
return end($segments); return end($segments);
} }
} }
// End of RoutingBase.php

View File

@ -124,7 +124,7 @@ class AnimeClientTestCase extends TestCase {
* @param array $supers * @param array $supers
* @return void * @return void
*/ */
public function setSuperGlobals($supers = []) public function setSuperGlobals($supers = []): void
{ {
$default = [ $default = [
'_SERVER' => $_SERVER, '_SERVER' => $_SERVER,
@ -139,7 +139,7 @@ class AnimeClientTestCase extends TestCase {
array_merge($default, $supers) array_merge($default, $supers)
); );
$this->container->setInstance('request', $request); $this->container->setInstance('request', $request);
$this->container->set('repsone', function() { $this->container->set('response', function() {
return new HttpResponse(); return new HttpResponse();
}); });
} }
@ -151,7 +151,7 @@ class AnimeClientTestCase extends TestCase {
* *
* @return string - contents of the data file * @return string - contents of the data file
*/ */
public function getMockFile() public function getMockFile(): string
{ {
$args = func_get_args(); $args = func_get_args();
array_unshift($args, TEST_DATA_DIR); array_unshift($args, TEST_DATA_DIR);

View File

@ -19,14 +19,6 @@ namespace Aviat\AnimeClient\Tests;
use Aviat\AnimeClient\RoutingBase; use Aviat\AnimeClient\RoutingBase;
class RoutingBaseTest extends AnimeClientTestCase { class RoutingBaseTest extends AnimeClientTestCase {
protected $routingBase;
public function setUp()
{
parent::setUp();
$this->routingBase = new RoutingBase($this->container);
}
public function dataSegments() public function dataSegments()
{ {
@ -49,7 +41,7 @@ class RoutingBaseTest extends AnimeClientTestCase {
/** /**
* @dataProvider dataSegments * @dataProvider dataSegments
*/ */
public function testSegments($requestUri, $path, $segments, $lastSegment) public function testSegments(string $requestUri, string $path, array $segments, $lastSegment): void
{ {
$this->setSuperGlobals([ $this->setSuperGlobals([
'_SERVER' => [ '_SERVER' => [
@ -57,13 +49,15 @@ class RoutingBaseTest extends AnimeClientTestCase {
] ]
]); ]);
$this->assertEquals($path, $this->routingBase->path(), "Path is invalid"); $routingBase = new RoutingBase($this->container);
$this->assertEquals($segments, $this->routingBase->segments(), "Segments array is invalid");
$this->assertEquals($lastSegment, $this->routingBase->lastSegment(), "Last segment is invalid"); $this->assertEquals($path, $routingBase->path(), "Path is invalid");
$this->assertEquals($segments, $routingBase->segments(), "Segments array is invalid");
$this->assertEquals($lastSegment, $routingBase->lastSegment(), "Last segment is invalid");
foreach($segments as $i => $value) foreach($segments as $i => $value)
{ {
$this->assertEquals($value, $this->routingBase->getSegment($i), "Segment {$i} is invalid"); $this->assertEquals($value, $routingBase->getSegment($i), "Segment {$i} is invalid");
} }
} }
} }