public function allowMethod($methods) { if (!is_array($methods)) { $methods = func_get_args(); } foreach ($methods as $method) { if ($this->is($method)) { return true; } } $allowed = strtoupper(implode(', ', $methods)); $e = new MethodNotAllowedException(); $e->responseHeader('Allow', $allowed); throw $e; }
/** * Test allowMethod throwing exception * * @return void */ public function testAllowMethodException() { $_SERVER['REQUEST_METHOD'] = 'PUT'; $request = new CakeRequest('/posts/edit/1'); try { $request->allowMethod('POST', 'DELETE'); $this->fail('An expected exception has not been raised.'); } catch (MethodNotAllowedException $e) { $this->assertEquals(array('Allow' => 'POST, DELETE'), $e->responseHeader()); } $this->setExpectedException('MethodNotAllowedException'); $request->allowMethod('POST'); }