Passed
Pull Request — master (#21)
by Pavel
06:33
created

RoutingTestCase::getInvalidRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Configuration;
4
5
use ScayTrase\Api\Cruds\Tests\WebTestCase;
6
use ScayTrase\Api\Cruds\Tests\StaticKernelTestTrait;
7
use Symfony\Component\Routing\RequestContext;
8
9
class RoutingTestCase extends WebTestCase
10
{
11
    use StaticKernelTestTrait;
12
13
    public function getValidRoutes()
14
    {
15
        return [
16
            'valid create POST' => ['/api/entity/my-entity/create', 'POST'],
17
            'valid get GET'     => ['/api/entity/my-entity/get', 'GET'],
18
            'valid get POST'    => ['/api/entity/my-entity/get', 'POST'],
19
            'valid update POST' => ['/api/entity/my-entity/update', 'POST'],
20
            'valid delete POST' => ['/api/entity/my-entity/delete', 'POST'],
21
            'valid search GET'  => ['/api/entity/my-entity/search', 'GET'],
22
            'valid search POST' => ['/api/entity/my-entity/search', 'POST'],
23
            'valid count GET'   => ['/api/entity/my-entity/count', 'GET'],
24
            'valid count POST'  => ['/api/entity/my-entity/count', 'POST'],
25
        ];
26
    }
27
28
    public function getInvalidRoutes()
29
    {
30
        return [
31
            'invalid create GET'  => ['/api/entity/my-entity/create', 'GET'],
32
            'invalid update GET'  => ['/api/entity/my-entity/update', 'GET'],
33
            'invalid delete POST' => ['/api/entity/my-entity/delete', 'GET'],
34
        ];
35
    }
36
37
    /**
38
     * @dataProvider getInvalidRoutes
39
     * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
40
     *
41
     * @param $path
42
     * @param $method
43
     */
44
    public function testPathNotMatches($path, $method)
45
    {
46
        $this->createRouter($method)->match($path);
47
    }
48
49
    /**
50
     * @dataProvider getValidRoutes
51
     *
52
     * @param string $path
53
     * @param string $method
54
     */
55
    public function testPathMatches($path, $method)
56
    {
57
        self::assertNotNull($this->createRouter($method)->match($path));
58
    }
59
60
    /**
61
     * @param $method
62
     *
63
     * @return object|\Symfony\Bundle\FrameworkBundle\Routing\Router
64
     */
65
    private function createRouter($method)
66
    {
67
        $container = self::$kernel->getContainer();
68
        $router    = $container->get('router');
69
70
        $context = new RequestContext('', $method);
71
        $router->getMatcher()->setContext($context);
72
73
        return $router;
74
    }
75
}
76