alltube/tests/UglyRouterTest.php

101 lines
2 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* UglyRouterTest class.
*/
namespace Alltube\Test;
use Alltube\Exception\ConfigException;
use Alltube\Exception\DependencyException;
use Alltube\UglyRouter;
use Slim\Http\Environment;
2017-01-10 22:39:58 +00:00
use Slim\Http\Request;
use SmartyException;
/**
* Unit tests for the UglyRouter class.
*/
class UglyRouterTest extends ContainerTest
{
/**
* UglyRouter instance.
*
* @var UglyRouter
*/
private $router;
/**
* Prepare tests.
*
* @throws ConfigException
* @throws DependencyException
* @throws SmartyException
*/
2019-11-30 13:08:18 +00:00
protected function setUp(): void
{
parent::setUp();
$this->router = new UglyRouter();
2021-02-07 11:42:03 +00:00
$this->router->map(['GET'], '/foo', [$this, 'fakeHandler'])->setName('foo');
}
/**
* Empty function that only exists so that our route can have a handler.
*
* @return void
*/
private function fakeHandler()
{
}
/**
* Test the dispatch() function.
2017-01-10 22:39:58 +00:00
*
* @return void
*/
public function testDispatch()
{
$this->assertEquals(
[1, 'route0', []],
$this->router->dispatch(
Request::createFromEnvironment(
Environment::mock(
[
'REQUEST_METHOD' => 'GET',
2021-02-07 11:42:03 +00:00
'QUERY_STRING' => 'page=foo',
]
)
)
)
);
}
/**
* Test the pathFor() function.
2017-01-10 22:39:58 +00:00
*
* @return void
*/
public function testPathFor()
{
$this->assertEquals(
'/?page=%2Ffoo',
$this->router->pathFor('foo', [], [])
);
}
/**
* Test the pathFor() function with a base path.
2017-01-10 22:39:58 +00:00
*
* @return void
*/
public function testPathForWithBasePath()
{
$this->router->setBasePath('/bar');
$this->assertEquals(
'/bar/?page=%2Ffoo',
$this->router->pathFor('foo', [], [])
);
}
}