1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Router\Tests\Router\Traits; |
4
|
|
|
|
5
|
|
|
use Nip\Router\Generator\UrlGenerator; |
6
|
|
|
use Nip\Router\Route\Route; |
7
|
|
|
use Nip\Router\RouteFactory; |
8
|
|
|
use Nip\Router\Router; |
9
|
|
|
use Nip\Router\Tests\AbstractTest; |
10
|
|
|
use Nip\Router\Tests\Fixtures\Application\Library\Router\Route\StandardRoute; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class HasGeneratorTraitTest |
14
|
|
|
* @package Nip\Router\Tests\Router\Traits |
15
|
|
|
*/ |
16
|
|
|
class HasGeneratorTraitTest extends AbstractTest |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function testGetGenerator() |
20
|
|
|
{ |
21
|
|
|
$router = new Router(); |
22
|
|
|
self::assertInstanceOf(UrlGenerator::class, $router->getGenerator()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
public function testAssemble() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$router = new Router(); |
28
|
|
|
$collection = $router->getRoutes(); |
29
|
|
|
|
30
|
|
|
RouteFactory::generateLiteralRoute($collection, "admin.index", Route::class, "/admin", "/index"); |
|
|
|
|
31
|
|
|
RouteFactory::generateStandardRoute($collection, "api.index", StandardRoute::class, "/api"); |
|
|
|
|
32
|
|
|
|
33
|
|
|
self::assertSame( |
34
|
|
|
'/admin/index?controller=posts', |
35
|
|
|
$router->assemble('admin.index', ['controller' => 'posts']) |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
self::assertSame( |
39
|
|
|
'/api/posts', |
40
|
|
|
$router->assemble('api.index', ['controller' => 'posts']) |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
self::assertSame( |
44
|
|
|
'/api/posts/create?test=true', |
45
|
|
|
$router->assemble('api.index', ['controller' => 'posts', 'action' => 'create', 'test' => 'true']) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testGenerate() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$router = new Router(); |
52
|
|
|
$collection = $router->getRoutes(); |
53
|
|
|
|
54
|
|
|
RouteFactory::generateLiteralRoute($collection, "admin.index", Route::class, "/admin", "/index"); |
|
|
|
|
55
|
|
|
RouteFactory::generateStandardRoute($collection, "api.index", StandardRoute::class, "/api"); |
|
|
|
|
56
|
|
|
|
57
|
|
|
self::assertSame( |
58
|
|
|
'/admin/index?controller=posts', |
59
|
|
|
$router->generate('admin.index', ['controller' => 'posts']) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
self::assertSame( |
63
|
|
|
'/api/posts', |
64
|
|
|
$router->generate('api.index', ['controller' => 'posts']) |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
self::assertSame( |
68
|
|
|
'/api/posts/create?param=test', |
69
|
|
|
$router->generate('api.index', ['controller' => 'posts','action' => 'create', 'param' => 'test']) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.