5
5
use Selami ;
6
6
use Zend \Diactoros \ServerRequestFactory ;
7
7
use ReflectionObject ;
8
+ use UnexpectedValueException ;
9
+ use InvalidArgumentException ;
8
10
9
11
class MyRouterClass extends \PHPUnit_Framework_TestCase
10
12
{
@@ -95,7 +97,12 @@ public function shouldCorrectlyInstantiateRouter()
95
97
$ router ->add ('post ' , '/json ' , 'app/redirect ' , 'redirect ' );
96
98
$ router ->add ('get ' , '/alias ' , 'app/alias ' , null , 'alias ' );
97
99
$ this ->assertInstanceOf ('Selami\Router ' , $ router );
98
- $ this ->assertAttributeContains ('GET ' , 'method ' , $ router , "Router didn't correctly return method as GET. " );
100
+ $ this ->assertAttributeContains (
101
+ 'GET ' ,
102
+ 'method ' ,
103
+ $ router ,
104
+ "Router didn't correctly return method as GET. "
105
+ );
99
106
}
100
107
101
108
/**
@@ -104,16 +111,17 @@ public function shouldCorrectlyInstantiateRouter()
104
111
public function shouldCorrectlyReturnRouteAndRouteAliases ()
105
112
{
106
113
$ router = new Selami \Router (
107
- $ this -> config [ ' default_return_type ' ] ,
114
+ ' json ' ,
108
115
$ this ->request ->getMethod (),
109
116
$ this ->request ->getUri ()->getPath (),
110
117
$ this ->config ['folder ' ]
111
118
);
112
119
113
- $ router ->add ('get ' , '/ ' , 'app/main ' ,null , 'home ' );
114
- $ router ->add ('get ' , '/json ' , 'app/json ' , 'json ' );
115
- $ router ->add ('post ' , '/json ' , 'app/redirect ' , 'redirect ' );
116
- $ router ->add ('get ' , '/alias ' , 'app/alias ' , null , 'alias ' );
120
+ $ router ->get ('/ ' , 'app/main ' , null , 'home ' );
121
+ $ router ->get ('/json ' , 'app/json ' , 'json ' );
122
+ $ router ->get ('/html ' , 'app/json ' );
123
+ $ router ->post ('/json ' , 'app/redirect ' , 'redirect ' );
124
+ $ router ->get ('/alias ' , 'app/alias ' , null , 'alias ' );
117
125
$ routeInfo = $ router ->getRoute ();
118
126
$ this ->assertArrayHasKey ('aliases ' , $ routeInfo , "Router didn't correctly return route data " );
119
127
@@ -123,9 +131,69 @@ public function shouldCorrectlyReturnRouteAndRouteAliases()
123
131
$ this ->assertEquals ('/alias ' , $ routeInfo ['aliases ' ]['alias ' ], "Router didn't correctly return aliases " );
124
132
$ this ->assertArrayHasKey ('controller ' , $ routeInfo ['route ' ], "Router didn't correctly return route data " );
125
133
$ this ->assertEquals ('app/alias ' , $ routeInfo ['route ' ]['controller ' ], "Router didn't correctly return router data " );
126
- $ this ->assertEquals ('html ' , $ routeInfo ['route ' ]['returnType ' ], "Router didn't correctly return router data " );
134
+ $ this ->assertEquals ('json ' , $ routeInfo ['route ' ]['returnType ' ], "Router didn't correctly return router data " );
135
+ }
136
+
137
+ /**
138
+ * @test
139
+ * @expectedException UnexpectedValueException
140
+ */
141
+ public function shouldThrowUnexpectedValueExceptionFor__callMethod ()
142
+ {
143
+ $ router = new Selami \Router (
144
+ $ this ->config ['default_return_type ' ],
145
+ $ this ->request ->getMethod (),
146
+ $ this ->request ->getUri ()->getPath (),
147
+ $ this ->config ['folder ' ]
148
+ );
149
+ $ router ->nonAvalibleHTTPMethod ('/ ' , 'app/main ' ,null , 'home ' );
150
+ }
151
+
152
+ /**
153
+ * @test
154
+ * @expectedException UnexpectedValueException
155
+ */
156
+ public function shouldThrowUnexpectedValueExceptionFor__constructorMethod ()
157
+ {
158
+ $ router = new Selami \Router (
159
+ $ this ->config ['default_return_type ' ],
160
+ 'UNEXPECTEDVALUE ' ,
161
+ $ this ->request ->getUri ()->getPath (),
162
+ $ this ->config ['folder ' ]
163
+ );
164
+ }
165
+
166
+ /**
167
+ * @test
168
+ * @expectedException UnexpectedValueException
169
+ */
170
+ public function shouldThrowUnexpectedValueExceptionForAddMethod ()
171
+ {
172
+ $ router = new Selami \Router (
173
+ $ this ->config ['default_return_type ' ],
174
+ $ this ->request ->getMethod (),
175
+ $ this ->request ->getUri ()->getPath (),
176
+ $ this ->config ['folder ' ]
177
+ );
178
+ $ router ->add ('nonAvailableHTTPMethod ' ,'/ ' , 'app/main ' ,null , 'home ' );
127
179
}
128
180
181
+ /**
182
+ * @test
183
+ * @expectedException InvalidArgumentException
184
+ */
185
+ public function shouldThrowInvalidArgumentExceptionForAddMethodIfREquestMEthotIsNotStringOrArray ()
186
+ {
187
+ $ router = new Selami \Router (
188
+ $ this ->config ['default_return_type ' ],
189
+ $ this ->request ->getMethod (),
190
+ $ this ->request ->getUri ()->getPath (),
191
+ $ this ->config ['folder ' ]
192
+ );
193
+ $ router ->add (200 ,'/ ' , 'app/main ' ,null , 'home ' );
194
+ }
195
+
196
+
129
197
/**
130
198
* @test
131
199
*/
0 commit comments