Esempio n. 1
0
 /**
  * Create a new mock request
  *
  * @param string $uri
  * @param string $req_method
  * @param array $parameters
  * @param array $cookies
  * @param array $server
  * @param array $files
  * @param string $body
  * @return void
  */
 public static function create($uri = '/', $req_method = 'GET', $parameters = array(), $cookies = array(), $server = array(), $files = array(), $body = null)
 {
     // Create a new Request object
     $request = new Request(array(), array(), $cookies, $server, $files, $body);
     // Reformat
     $req_method = strtoupper(trim($req_method));
     // Set its URI and Method
     $request->server()->set('REQUEST_URI', $uri);
     $request->server()->set('REQUEST_METHOD', $req_method);
     // Set our parameters
     switch ($req_method) {
         case 'POST':
         case 'PUT':
         case 'PATCH':
         case 'DELETE':
             $request->paramsPost()->replace($parameters);
             break;
         default:
             $request->paramsGet()->replace($parameters);
             break;
     }
     return $request;
 }
Esempio n. 2
0
 public function testMethodOverride()
 {
     // Test data
     $method = 'POST';
     $override_method = 'TRACE';
     $weird_override_method = 'DELETE';
     $request = new Request();
     $request->server()->set('REQUEST_METHOD', $method);
     $request->server()->set('X_HTTP_METHOD_OVERRIDE', $override_method);
     $this->assertSame($override_method, $request->method());
     $this->assertTrue($request->method($override_method));
     $this->assertTrue($request->method(strtolower($override_method)));
     $request->server()->remove('X_HTTP_METHOD_OVERRIDE');
     $request->paramsPost()->set('_method', $weird_override_method);
     $this->assertSame($weird_override_method, $request->method());
     $this->assertTrue($request->method($weird_override_method));
     $this->assertTrue($request->method(strtolower($weird_override_method)));
 }