HasMatcherTraitTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 54
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testNotFound() 0 8 1
A testRouteDynamic() 0 21 1
A testRouteLiteral() 0 19 1
1
<?php
2
3
namespace Nip\Router\Tests\Legacy\Router\Traits;
4
5
use Nip\Http\Request;
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
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
12
13
/**
14
 * Class HasMatcherTraitTest
15
 * @package Nip\Router\Tests\Legacy\Router\Traits
16
 */
17
class HasMatcherTraitTest extends AbstractTest
18
{
19
    public function testNotFound()
20
    {
21
        $router = new Router();
22
        $router->initRouteCollection();
23
        self::expectException(ResourceNotFoundException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        self::/** @scrutinizer ignore-call */ 
24
              expectException(ResourceNotFoundException::class);
Loading history...
24
25
        $request = Request::create('/404');
26
        $router->route($request);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

26
        /** @scrutinizer ignore-deprecated */ $router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
27
    }
28
29
    public function testRouteLiteral()
30
    {
31
        $router = new Router();
32
        $router->initRouteCollection();
33
        $collection = $router->getRoutes();
34
35
        RouteFactory::generateLiteralRoute($collection, "admin.index", Route::class, "/admin", "/index");
36
        RouteFactory::generateLiteralRoute($collection, "api.index", Route::class, "/api", "/index");
37
38
        $request = Request::create('/api/index');
39
        $params = $router->route($request);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
        $params = /** @scrutinizer ignore-deprecated */ $router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40
        self::assertEquals(['_route' => 'api.index'], $params);
41
42
        $currentRoute = $router->getCurrent();
43
        self::assertEquals('api.index', $currentRoute);
44
45
        $request = Request::create('/admin/index');
46
        $router->route($request);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        /** @scrutinizer ignore-deprecated */ $router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
        self::assertEquals('admin.index', $router->getCurrent());
48
    }
49
50
    public function testRouteDynamic()
51
    {
52
        $router = new Router();
53
        $router->initRouteCollection();
54
        $collection = $router->getRoutes();
55
56
        RouteFactory::generateStandardRoute($collection, "admin.standard", StandardRoute::class, "/admin",
57
            '/:controller/:action', ['module' => 'admin']);
58
        RouteFactory::generateStandardRoute($collection, "api.standard", StandardRoute::class, "/api",
59
            '/:controller/:action', ['module' => 'api']);
60
61
        $request = Request::create('/api/pages/delete');
62
        self::assertEquals(
63
            ['module' => 'api', 'controller' => 'pages', 'action' => 'delete','_route' => 'api.standard'],
64
            $router->route($request)
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

64
            /** @scrutinizer ignore-deprecated */ $router->route($request)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
65
        );
66
67
        $request = Request::create('/admin/pages/delete');
68
        self::assertEquals(
69
            ['module' => 'admin', 'controller' => 'pages', 'action' => 'delete', '_route' => 'admin.standard'],
70
            $router->route($request)
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

70
            /** @scrutinizer ignore-deprecated */ $router->route($request)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
        );
72
    }
73
}
74