|
2 | 2 |
|
3 | 3 | namespace Test\DevCoder; |
4 | 4 |
|
| 5 | +use DevCoder\Exception\RouteNotFound; |
5 | 6 | use PHPUnit\Framework\TestCase; |
6 | 7 | use DevCoder\Route; |
7 | 8 | use DevCoder\Router; |
@@ -32,17 +33,36 @@ public function __construct($name = null, array $data = [], $dataName = '') |
32 | 33 | ->add($routeArticleWithParams); |
33 | 34 | } |
34 | 35 |
|
| 36 | + public function testMatchRoute() { |
| 37 | + |
| 38 | + $route = $this->router->matchFromPath('/view/article/25', 'GET'); |
| 39 | + $this->assertInstanceOf(Route::class, $route); |
| 40 | + |
| 41 | + $this->assertNotEmpty($route->getController()); |
| 42 | + $this->assertNotEmpty($route->getMethods()); |
| 43 | + $this->assertSame(['id' => '25'], $route->getVars()); |
| 44 | + |
| 45 | + |
| 46 | + $this->assertInstanceOf(Route::class, $this->router->matchFromPath('/home', 'GET')); |
| 47 | + $this->expectException(RouteNotFound::class); |
| 48 | + $this->router->matchFromPath('/home', 'PUT'); |
| 49 | + |
| 50 | + } |
| 51 | + |
35 | 52 | public function testGenerateUrl() { |
36 | 53 |
|
37 | 54 | $urlHome = $this->router->generateUri('home_page'); |
38 | 55 | $urlArticle = $this->router->generateUri('article_page'); |
39 | 56 | $urlArticleWithParam = $this->router->generateUri('article_page_by_id', ['id' => 25]); |
40 | 57 | $routeArticleWithParams = $this->router->generateUri('article_page_by_id_and_page', ['id' => 25, 'page' => 3]); |
41 | 58 |
|
42 | | - $this->assertEquals($urlHome, '/home'); |
43 | | - $this->assertEquals($urlArticle, '/view/article'); |
44 | | - $this->assertEquals($urlArticleWithParam, '/view/article/25'); |
45 | | - $this->assertEquals($routeArticleWithParams, '/view/article/25/3'); |
| 59 | + $this->assertSame($urlHome, '/home'); |
| 60 | + $this->assertSame($urlArticle, '/view/article'); |
| 61 | + $this->assertSame($urlArticleWithParam, '/view/article/25'); |
| 62 | + $this->assertSame($routeArticleWithParams, '/view/article/25/3'); |
| 63 | + |
| 64 | + $this->expectException(\InvalidArgumentException::class); |
| 65 | + $this->router->generateUri('article_page_by_id_and_page', ['id' => 25]); |
46 | 66 |
|
47 | 67 | } |
48 | 68 | } |
0 commit comments