Skip to content

Commit 298537b

Browse files
authored
Merge pull request #9 from peter279k/issue_#8
Issue #8
2 parents dc50f52 + ee5e626 commit 298537b

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

tests/RouterTest.php

+38-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,45 @@ public function testGetNotFoundRoute()
5050
$response = $this->client->send($request);
5151
}
5252

53+
public function testGetControllerRoute()
54+
{
55+
$request = $this->client->createRequest('GET', 'http://localhost:5000/controllers');
56+
$response = $this->client->send($request);
57+
58+
$this->assertSame('controller route', (string) $response->getBody());
59+
}
60+
5361
public function testInit()
5462
{
55-
$this->assertInstanceOf('\Buki\Router', new Router());
63+
$this->assertInstanceOf('\\Buki\\Router', new Router());
64+
}
65+
66+
public function testGetRoutes()
67+
{
68+
$params = [
69+
'paths' => [
70+
'controllers' => 'controllers/',
71+
],
72+
'namespaces' => [
73+
'controllers' => 'Controllers\\',
74+
],
75+
'base_folder' => __DIR__,
76+
'main_method' => 'main',
77+
];
78+
$router = new Router($params);
79+
80+
$router->get('/', function() {
81+
return 'Hello World!';
82+
});
83+
84+
$router->get('/controllers', 'TestController@main');
85+
86+
$routes = $router->getRoutes();
87+
88+
$this->assertCount(2, $routes);
89+
$this->assertInstanceOf('\\Closure', $routes[0]['callback']);
90+
$this->assertSame('TestController@main', $routes[1]['callback']);
91+
$this->assertSame('GET', $routes[0]['method']);
92+
$this->assertSame('GET', $routes[1]['method']);
5693
}
5794
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Controllers;
4+
5+
class TestController
6+
{
7+
public function main()
8+
{
9+
return 'controller route';
10+
}
11+
}

tests/fixtures/server.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@
22

33
require __DIR__ . '/../../vendor/autoload.php';
44

5-
$router = new Buki\Router();
5+
use Buki\Router;
6+
7+
$params = [
8+
'paths' => [
9+
'controllers' => 'controllers/',
10+
],
11+
'namespaces' => [
12+
'controllers' => 'Controllers\\',
13+
],
14+
'base_folder' => __DIR__,
15+
'main_method' => 'main',
16+
];
17+
18+
$router = new Router($params);
619

720
$router->get('/', function() {
821
return 'Hello World!';
922
});
1023

24+
$router->get('/controllers', 'TestController@main');
25+
1126
$router->run();

0 commit comments

Comments
 (0)