RouteTest::testEmptyRoutePath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * apparat-server
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Server
8
 * @subpackage  Apparat\Server\Tests
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Server\Tests;
38
39
use Apparat\Dev\Tests\AbstractTest;
40
use Apparat\Server\Ports\Route\Route;
41
42
/**
43
 * Route test
44
 *
45
 * @package Apparat\Server
46
 * @subpackage Apparat\Server\Tests
47
 */
48
class RouteTest extends AbstractTest
49
{
50
    /**
51
     * Test empty route verbs
52
     *
53
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
54
     * @expectedExceptionCode 1464520768
55
     */
56
    public function testEmptyRouteVerbs()
57
    {
58
        new Route('', 'name', 'path', 'action');
59
    }
60
61
    /**
62
     * Test invalid route verb
63
     *
64
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
65
     * @expectedExceptionCode 1464520896
66
     */
67
    public function testInvalidRouteVerb()
68
    {
69
        new Route('INVALID', 'name', 'path', 'action');
70
    }
71
72
    /**
73
     * Test empty route name
74
     *
75
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
76
     * @expectedExceptionCode 1464521013
77
     */
78
    public function testEmptyRouteName()
79
    {
80
        new Route(Route::GET, '', 'path', 'action');
81
    }
82
83
    /**
84
     * Test empty route path
85
     *
86
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
87
     * @expectedExceptionCode 1464521073
88
     */
89
    public function testEmptyRoutePath()
90
    {
91
        new Route(Route::GET, 'test', '', 'action');
92
    }
93
94
    /**
95
     * Test empty route action
96
     *
97
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
98
     * @expectedExceptionCode 1464521136
99
     */
100
    public function testEmptyRouteAction()
101
    {
102
        new Route(Route::GET, 'test', 'path', '');
103
    }
104
105
    /**
106
     * Test invalid route action class
107
     *
108
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
109
     * @expectedExceptionCode 1464521937
110
     */
111
    public function testInvalidRouteActionClass()
112
    {
113
        new Route(Route::GET, 'test', 'path', 'InvalidRouteActionClass');
114
    }
115
116
    /**
117
     * Test invalid route action interface
118
     *
119
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
120
     * @expectedExceptionCode 1464522202
121
     */
122
    public function testInvalidRouteActionInterface()
123
    {
124
        new Route(Route::GET, 'test', 'path', \stdClass::class);
125
    }
126
127
    /**
128
     * Test invalid route action
129
     *
130
     * @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException
131
     * @expectedExceptionCode 1464521506
132
     */
133
    public function testInvalidRouteAction()
134
    {
135
        new Route(Route::GET, 'test', 'path', [true]);
136
    }
137
138
    /**
139
     * Test the route setters
140
     */
141
    public function testRouteSetters()
142
    {
143
        $route = new Route(
144
            Route::GET,
145
            'test',
146
            'path',
147
            function () {
148
            }
149
        );
150
        $route->setDefaults(['key' => 'value']);
151
        $route->setWildcard('wildcard');
152
        $route->setHost('apparat.tools');
153
        $route->setAccepts(['application/json']);
154
        $route->setVerbs([Route::POST]);
155
        $route->setSecure(true);
156
        $route->setAuth('credentials');
157
        $route->setExtras(['key' => 'value']);
158
        $this->assertInstanceOf(Route::class, $route);
159
    }
160
}
161