@@ 145-162 (lines=18) @@ | ||
142 | /** |
|
143 | * Tests that the CLI routing functionality works. |
|
144 | */ |
|
145 | public function testStandardCliRoute() |
|
146 | { |
|
147 | $config = $this->getStandardConfig(); |
|
148 | $router = new SnappyRouter(new Config($config)); |
|
149 | ||
150 | $_SERVER['argv'] = array( |
|
151 | 'dummyScript.php', |
|
152 | '--task', |
|
153 | 'TestTask', |
|
154 | '--action', |
|
155 | 'testMethod' |
|
156 | ); |
|
157 | $_SERVER['argc'] = count($_SERVER['argv']); |
|
158 | $response = $router->handleRoute(); |
|
159 | ||
160 | $expected = 'Hello World'.PHP_EOL; |
|
161 | $this->assertEquals($expected, $response); |
|
162 | } |
|
163 | ||
164 | /** |
|
165 | * Tests a CLI route that throws an exception. |
|
@@ 167-184 (lines=18) @@ | ||
164 | /** |
|
165 | * Tests a CLI route that throws an exception. |
|
166 | */ |
|
167 | public function testCliRouteWithException() |
|
168 | { |
|
169 | $config = $this->getStandardConfig(); |
|
170 | $router = new SnappyRouter(new Config($config)); |
|
171 | ||
172 | $_SERVER['argv'] = array( |
|
173 | 'dummyScript.php', |
|
174 | '--task', |
|
175 | 'TestTask', |
|
176 | '--action', |
|
177 | 'throwsException' |
|
178 | ); |
|
179 | $_SERVER['argc'] = count($_SERVER['argv']); |
|
180 | $response = $router->handleRoute(); |
|
181 | ||
182 | $expected = 'An exception was thrown.'.PHP_EOL; |
|
183 | $this->assertEquals($expected, $response); |
|
184 | } |
|
185 | ||
186 | /** |
|
187 | * Tests that a CLI route with no appropriate handlers throws an |
|
@@ 190-207 (lines=18) @@ | ||
187 | * Tests that a CLI route with no appropriate handlers throws an |
|
188 | * exception. |
|
189 | */ |
|
190 | public function testCliRouteWithNoHandler() |
|
191 | { |
|
192 | $config = $this->getStandardConfig(); |
|
193 | $router = new SnappyRouter(new Config($config)); |
|
194 | ||
195 | $_SERVER['argv'] = array( |
|
196 | 'dummyScript.php', |
|
197 | '--task', |
|
198 | 'NotDefinedTask', |
|
199 | '--action', |
|
200 | 'anyAction' |
|
201 | ); |
|
202 | $_SERVER['argc'] = count($_SERVER['argv']); |
|
203 | $response = $router->handleRoute(); |
|
204 | ||
205 | $expected = 'No CLI handler registered.'.PHP_EOL; |
|
206 | $this->assertEquals($expected, $response); |
|
207 | } |
|
208 | } |
|
209 |