Create Core/Router and public/index then test the Router
This commit is contained in:
69
_tests/unit/RouterTest.php
Normal file
69
_tests/unit/RouterTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace Core;
|
||||
|
||||
class RouterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for matchingRouteSuccess
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function routeProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'',
|
||||
['controller' => 'Data', 'action' => 'index'],
|
||||
'',
|
||||
['controller' => 'Data', 'action' => 'index']
|
||||
],
|
||||
[
|
||||
'{controller}/{action}',
|
||||
[],
|
||||
'home/index',
|
||||
['controller' => 'home', 'action' => 'index']
|
||||
],
|
||||
[
|
||||
'{controller}/{id:\d+}/{action}',
|
||||
[],
|
||||
'home/150/index',
|
||||
['controller' => 'home', 'action' => 'index', 'id' => '150']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @test
|
||||
* @dataProvider routeProvider
|
||||
*/
|
||||
public function matchingRouteSuccess($route, $params, $url, $expected_param)
|
||||
{
|
||||
$router = new Router();
|
||||
|
||||
$router->add($route, $params);
|
||||
|
||||
$this->assertTrue($router->match($url));
|
||||
|
||||
$this->assertEquals($expected_param, $router->getParams());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @test
|
||||
* @dataProvider routeProvider
|
||||
*/
|
||||
public function dispatchingRouteSuccess($route, $params, $url)
|
||||
{
|
||||
// $url = 'home/index';
|
||||
|
||||
$router = new Router();
|
||||
|
||||
// $router->add('{controller}/{action}');
|
||||
$router->add($route, $params);
|
||||
|
||||
$this->assertTrue($router->match($url));
|
||||
|
||||
$this->assertFalse($router->dispatch($url));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user