Example #1
0
 /**
  * Test registering and then unregistering all response filter callbacks
  * for a specific status code, and ensure that they are not executed.
  *
  * @return void
  * @runInSeparateProcess
  */
 public function testUnregisterAllFilterCallbacks()
 {
     $config = $this->buildMockConfiguration(array(array('path' => '/test', 'httpMethod' => 'GET', 'resourceClassName' => 'Sonno\\Test\\Application\\Asset\\TestResource', 'resourceMethodName' => 'causeError', 'produces' => array('text/plain'), 'contexts' => array(), 'pathParams' => array(), 'queryParams' => array())), '/service/v1');
     $request = $this->buildMockRequest('GET', '/service/v1/nonexistent');
     $app = new Application($config);
     $app->registerResponseFilter(404, function ($request, $response) {
         /** @var $response \Sonno\Http\Response\Response */
         $response->setHeaders(array('Content-Type' => 'text/html'));
     });
     $app->registerResponseFilter(404, function ($request, $response) {
         /** @var $response \Sonno\Http\Response\Response */
         $response->setContent('Sorry, but that resource does not exist');
     });
     $app->unregisterResponseFilter(404);
     $response = $app->run($request);
     $this->assertNull($response->getContent());
 }