Пример #1
0
 public function testBasicRoute()
 {
     // Setup our request
     $this->setTestURI('/basic/route');
     $paulus = new Paulus($this->config);
     // Define our endpoint
     Router::route('/basic/route', function ($request, $response) {
         $response->data = array('success' => true);
     });
     $output = $this->runAndGetOutput($paulus);
     // Assertions
     $this->assertEquals(200, $output->meta->status_code);
     $this->assertEquals('OK', $output->meta->status);
     $this->assertEquals(array(), (array) $output->meta->more_info);
     $this->assertEquals(true, $output->data->success);
     $this->assertEquals('', $output->meta->message);
 }
Пример #2
0
 public function testWrongMethodException()
 {
     // Setup our request
     $this->setTestURI('/this-endpoint-requires-POST-or-DELETE');
     $this->setTestMethod('GET');
     // Define our endpoint
     Router::route(array('POST', 'DELETE'), '/this-endpoint-requires-POST-or-DELETE', function () {
         echo 'fail';
     });
     $output = $this->runAndGetOutput();
     // Assertions
     $this->assertEquals(405, $output->meta->status_code);
     $this->assertEquals('METHOD_NOT_ALLOWED', $output->meta->status);
     $this->assertEquals(array('POST', 'DELETE'), $output->meta->more_info->possible_methods);
     $this->assertEquals(array(), (array) $output->data);
     $this->assertStringStartsWith('The wrong method', $output->meta->message);
 }
Пример #3
0
 /**
  * run
  *
  * Run the app
  * 
  * @access public
  * @return void
  */
 public function run()
 {
     // Setup our default error route responders
     $this->setup_error_routes();
     // To always be RESTful, create a last-hit route responder to respond in our designated format ALWAYS
     Router::route(function ($request, $response, $service, $matches) {
         // ALWAYS respond with our formatting function
         Router::app()->api_respond();
     });
     // Finally, call "dispatch" to have our App's Router route the request appropriately
     Router::dispatch(substr($_SERVER['REQUEST_URI'], strlen(rtrim($this->config['app-meta']['base_url'], '/'))));
 }