RestHandlerTest::restPathsProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 41
rs 9.264
c 0
b 0
f 0
1
<?php
2
3
namespace Vectorface\SnappyRouterTests\Handler;
4
5
use PHPUnit\Framework\TestCase;
6
use Vectorface\SnappyRouter\Config\Config;
7
use Vectorface\SnappyRouter\Handler\RestHandler;
8
9
/**
10
 * A test for the RestHandler class.
11
 * @copyright Copyright (c) 2014, VectorFace, Inc.
12
 * @author Dan Bruce <[email protected]>
13
 */
14
class RestHandlerTest extends TestCase
15
{
16
    /**
17
     * An overview of how to use the RestHandler class.
18
     * @test
19
     */
20
    public function synopsis()
21
    {
22
        $options = array(
23
            RestHandler::KEY_BASE_PATH => '/',
24
            Config::KEY_CONTROLLERS => array(
25
                'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController'
26
            )
27
        );
28
        $handler = new RestHandler($options);
29
        $this->assertTrue($handler->isAppropriate('/v1/test', array(), array(), 'GET'));
30
        $result = json_decode($handler->performRoute());
31
        $this->assertTrue(empty($result));
32
    }
33
34
    /**
35
     * Tests the possible paths that could be handled by the RestHandler.
36
     * @dataProvider restPathsProvider
37
     */
38
    public function testRestHandlerHandlesPath($expected, $path)
39
    {
40
        $options = array(
41
            RestHandler::KEY_BASE_PATH => '/',
42
            Config::KEY_CONTROLLERS => array(
43
                'TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController'
44
            )
45
        );
46
        $handler = new RestHandler($options);
47
        $this->assertEquals($expected, $handler->isAppropriate($path, array(), array(), 'GET'));
48
    }
49
50
    /**
51
     * The data provider for testing various paths against the RestHandler.
52
     */
53
    public function restPathsProvider()
54
    {
55
        return array(
56
            array(
57
                true,
58
                '/v1/test'
59
            ),
60
            array(
61
                true,
62
                '/v1.2/test'
63
            ),
64
            array(
65
                true,
66
                '/v1.2/Test'
67
            ),
68
            array(
69
                true,
70
                '/v1.2/test/1234'
71
            ),
72
            array(
73
                true,
74
                '/v1.2/test/someAction'
75
            ),
76
            array(
77
                true,
78
                '/v1.2/test/1234/someAction'
79
            ),
80
            array(
81
                false,
82
                '/v1.2'
83
            ),
84
            array(
85
                true,
86
                '/v1.2/noController'
87
            ),
88
            array(
89
                false,
90
                '/v1.2/1234/5678'
91
            )
92
        );
93
    }
94
}
95