Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 298537b

Browse files
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‎

Lines changed: 38 additions & 1 deletion
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
}
Lines changed: 11 additions & 0 deletions
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‎

Lines changed: 16 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /