Passed
Push — master ( 035a69...ef3bdc )
by Kirill
03:22
created

MultipleActionsTest::testUriGeneration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Router;
13
14
use Spiral\Router\Exception\UndefinedRouteException;
15
use Spiral\Router\Route;
16
use Spiral\Router\Target\Action;
17
use Spiral\Tests\Router\Fixtures\TestController;
18
use Laminas\Diactoros\ServerRequest;
19
use Laminas\Diactoros\Uri;
20
21
class MultipleActionsTest extends BaseTest
22
{
23
    public function testRouteException(): void
24
    {
25
        $this->expectException(UndefinedRouteException::class);
26
27
        $router = $this->makeRouter();
28
        $router->setRoute(
29
            'action',
30
            new Route('/<action>/<id>', new Action(TestController::class, ['test', 'id']))
31
        );
32
33
        $router->handle(new ServerRequest());
34
    }
35
36
    public function testRoute(): void
37
    {
38
        $router = $this->makeRouter();
39
        $router->setRoute(
40
            'action',
41
            new Route('/<action>[/<id>]', new Action(TestController::class, ['test', 'id']))
42
        );
43
44
        $response = $router->handle(new ServerRequest([], [], new Uri('/test')));
45
        $this->assertSame(200, $response->getStatusCode());
46
        $this->assertSame('hello world', (string)$response->getBody());
47
48
        $response = $router->handle(new ServerRequest([], [], new Uri('/id/900')));
49
        $this->assertSame(200, $response->getStatusCode());
50
        $this->assertSame('900', (string)$response->getBody());
51
    }
52
53
    public function testUriGeneration(): void
54
    {
55
        $router = $this->makeRouter();
56
        $router->setRoute(
57
            'action',
58
            new Route('/<action>[/<id>]', new Action(TestController::class, ['test', 'id']))
59
        );
60
61
        $uri = $router->uri('action/test');
62
        $this->assertSame('/test', $uri->getPath());
63
64
        $uri = $router->uri('action/id', ['id' => 100]);
65
        $this->assertSame('/id/100', $uri->getPath());
66
    }
67
}
68