Version 5.1 - All the GraphQL #32
@ -45,10 +45,10 @@ final class Dispatcher extends RoutingBase {
|
||||
protected $matcher;
|
||||
|
||||
/**
|
||||
* Class wrapper for input superglobals
|
||||
* @var \Psr\Http\Message\ServerRequestInterface
|
||||
* Routing array
|
||||
* @var array
|
||||
*/
|
||||
protected $request;
|
||||
protected $routes;
|
||||
|
||||
/**
|
||||
* Routes added to router
|
||||
@ -67,8 +67,7 @@ final class Dispatcher extends RoutingBase {
|
||||
$router = $this->container->get('aura-router');
|
||||
$this->router = $router->getMap();
|
||||
$this->matcher = $router->getMatcher();
|
||||
$this->request = $container->get('request');
|
||||
|
||||
$this->routes = $this->config->get('routes');
|
||||
$this->outputRoutes = $this->setupRoutes();
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ class RoutingBase {
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Routing array
|
||||
* @var array
|
||||
* Class wrapper for input superglobals
|
||||
* @var \Psr\Http\Message\ServerRequestInterface
|
||||
*/
|
||||
protected $routes;
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -56,7 +56,7 @@ class RoutingBase {
|
||||
{
|
||||
$this->container = $container;
|
||||
$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
|
||||
{
|
||||
$request = $this->container->get('request');
|
||||
$path = $request->getUri()->getPath();
|
||||
$path = $this->request->getUri()->getPath();
|
||||
$cleanedPath = $this->string($path)
|
||||
->replace('%20', '')
|
||||
->trim()
|
||||
@ -116,5 +115,4 @@ class RoutingBase {
|
||||
$segments = $this->segments();
|
||||
return end($segments);
|
||||
}
|
||||
}
|
||||
// End of RoutingBase.php
|
||||
}
|
@ -124,7 +124,7 @@ class AnimeClientTestCase extends TestCase {
|
||||
* @param array $supers
|
||||
* @return void
|
||||
*/
|
||||
public function setSuperGlobals($supers = [])
|
||||
public function setSuperGlobals($supers = []): void
|
||||
{
|
||||
$default = [
|
||||
'_SERVER' => $_SERVER,
|
||||
@ -139,7 +139,7 @@ class AnimeClientTestCase extends TestCase {
|
||||
array_merge($default, $supers)
|
||||
);
|
||||
$this->container->setInstance('request', $request);
|
||||
$this->container->set('repsone', function() {
|
||||
$this->container->set('response', function() {
|
||||
return new HttpResponse();
|
||||
});
|
||||
}
|
||||
@ -151,7 +151,7 @@ class AnimeClientTestCase extends TestCase {
|
||||
*
|
||||
* @return string - contents of the data file
|
||||
*/
|
||||
public function getMockFile()
|
||||
public function getMockFile(): string
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_unshift($args, TEST_DATA_DIR);
|
||||
|
@ -19,14 +19,6 @@ namespace Aviat\AnimeClient\Tests;
|
||||
use Aviat\AnimeClient\RoutingBase;
|
||||
|
||||
class RoutingBaseTest extends AnimeClientTestCase {
|
||||
|
||||
protected $routingBase;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->routingBase = new RoutingBase($this->container);
|
||||
}
|
||||
|
||||
public function dataSegments()
|
||||
{
|
||||
@ -49,7 +41,7 @@ class RoutingBaseTest extends AnimeClientTestCase {
|
||||
/**
|
||||
* @dataProvider dataSegments
|
||||
*/
|
||||
public function testSegments($requestUri, $path, $segments, $lastSegment)
|
||||
public function testSegments(string $requestUri, string $path, array $segments, $lastSegment): void
|
||||
{
|
||||
$this->setSuperGlobals([
|
||||
'_SERVER' => [
|
||||
@ -57,13 +49,15 @@ class RoutingBaseTest extends AnimeClientTestCase {
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals($path, $this->routingBase->path(), "Path is invalid");
|
||||
$this->assertEquals($segments, $this->routingBase->segments(), "Segments array is invalid");
|
||||
$this->assertEquals($lastSegment, $this->routingBase->lastSegment(), "Last segment is invalid");
|
||||
$routingBase = new RoutingBase($this->container);
|
||||
|
||||
$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)
|
||||
{
|
||||
$this->assertEquals($value, $this->routingBase->getSegment($i), "Segment {$i} is invalid");
|
||||
$this->assertEquals($value, $routingBase->getSegment($i), "Segment {$i} is invalid");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user