Create Core/Router and public/index then test the Router

This commit is contained in:
2017-08-31 08:59:49 +07:00
parent 6b5fe0eadf
commit ffea1b6b6c
3 changed files with 173 additions and 0 deletions

View 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));
}
}