Example #1
0
 public function testMethodCatchallRoute()
 {
     // Setup our request
     $this->setTestURI('/');
     $this->setTestMethod('PUT');
     $paulus = new Paulus($this->config);
     // Define our endpoint
     Router::put(function ($request, $response) {
         $response->data = array('putcatchall' => true);
     });
     $output = $this->runAndGetOutput($paulus);
     // Assertions
     $this->assertEquals(true, $output->data->putcatchall);
 }
Example #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);
 }
Example #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'], '/'))));
 }