Beispiel #1
0
 public function test_create_from_request()
 {
     $request = new HttpRequest();
     $request->setContent('foo');
     $task = FakeTask::fromHttpRequest($request);
     $this->assertEquals('foo', $task->getContent());
 }
Beispiel #2
0
 public function test_get_token()
 {
     $request = new HttpRequest();
     $auth = new HttpBasicAuth($request);
     $parser = new BasicAuthParser();
     $parser->setToken($request->getHeaders(), 'foo');
     $this->assertEquals('foo', $auth->getToken());
 }
Beispiel #3
0
 public function test_data_type()
 {
     $request = new HttpRequest();
     $data = new JsonData($request);
     $this->assertNotEquals($data->getDataType(), $request->getContentType());
     $this->assertEquals(HttpDataType::JSON, $data->getDataType());
     $data->setDataType('foo');
     $this->assertEquals('foo', $data->getDataType());
 }
 public function test_write_username_and_password()
 {
     $headers = new HttpHeaders();
     $parser = new ReceivedHeadersParser();
     $source = ['PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar'];
     $parser->writeBasicAuthHeaders($headers, $source);
     $request = new HttpRequest();
     new HttpBasicAuth($request, 'foo', 'bar');
     $this->assertEquals($request->getHeaders()->toDistinctArray(), $headers->toDistinctArray());
 }
Beispiel #5
0
 public function test_data_type()
 {
     $request = new HttpRequest();
     $data = new UrlEncodedData($request);
     $this->assertNotEquals($data->getDataType(), $request->getContentType());
     $this->assertEquals(HttpDataType::URL_ENCODED, $data->getDataType());
     $this->assertTrue($data->isUrlEncoded());
     $this->assertFalse($data->isMultipart());
     $data->setDataType(HttpDataType::MULTI_PART);
     $this->assertEquals(HttpDataType::MULTI_PART, $data->getDataType());
     $this->assertTrue($data->isMultipart());
     $this->assertFalse($data->isUrlEncoded());
 }
 public function test_send_and_receive_cookies()
 {
     $client = new HttpClient();
     $url = self::getUrl();
     $url->addPath('cookies');
     $request = new HttpRequest(HttpRequestMethod::GET, $url);
     $request->getCookieJar()->set('foo', 'bar');
     $request->getCookieJar()->set('bar', 'foo');
     $response = $client->send($request);
     $cookie = $response->getCookies()->findByName('yolo');
     $this->assertNotNull($cookie);
     $this->assertEquals('swag', $cookie->getValue());
     $this->assertEquals('bar', $response->getCookies()->findByName('foo')->getValue());
     $this->assertEquals('foo', $response->getCookies()->findByName('bar')->getValue());
 }
Beispiel #7
0
 public function test_getters_and_setters()
 {
     $request = new HttpRequest();
     $cookies = new Cookies($request);
     $cookie = new Cookie('foo', 'bar');
     $this->assertEquals(0, count($cookies->toArray()));
     $this->assertNull($cookies->findByName('foo'));
     $cookies->add($cookie);
     $this->assertEquals(1, count($cookies->toArray()));
     $this->assertNotNull($cookies->findByName('foo'));
     $this->assertTrue($cookie === $cookies->findByName('foo'));
     $cookies->add(new Cookie('yolo', 'swag'));
     $this->assertEquals(2, count($cookies->toArray()));
     $cookies->removeByName('bar');
     $this->assertEquals(2, count($cookies->toArray()));
     $cookies->removeByName('yolo');
     $this->assertEquals(1, count($cookies->toArray()));
     $this->assertEquals($cookie->toString(), $request->getHeaders()->find('set-cookie'));
 }
Beispiel #8
0
 /**
  * @param array|null $server
  * @param IReceivedRequestParser|null $parser
  */
 public function __construct(array $server = null, IReceivedRequestParser $parser = null)
 {
     parent::__construct();
     if ($server === null) {
         $server = $_SERVER;
     }
     if ($parser === null) {
         $parser = $this->createParser();
     }
     $parser->parseRequest($server, $this);
 }
Beispiel #9
0
 public function test_switch_env_in_env_aware_mode()
 {
     $app = new HttpApp();
     $request = new HttpRequest();
     $app->handleRequest($request);
     $this->assertEquals('dev', $app->getEnvironment());
     $request = new HttpRequest();
     $app->setDebug(false);
     $request->getHeaders()->set('x-env', 'prod');
     $app->handleRequest($request);
     $this->assertEquals('dev', $app->getEnvironment());
     $this->assertNull($request->getHeaders()->find('x-env'));
     $request = new HttpRequest();
     $request->getHeaders()->set('x-env', 'prod');
     $app->setDebug(true);
     $app->handleRequest($request);
     $this->assertEquals('prod', $app->getEnvironment());
     $this->assertNull($request->getHeaders()->find('x-env'));
     $request = new HttpRequest();
     $request->getUrl()->getQuery()->set('env', 'stage');
     $app->setDebug(true);
     $app->handleRequest($request);
     $this->assertEquals('stage', $app->getEnvironment());
     $this->assertNull($request->getUrl()->getQuery()->get('env'));
     $request = new HttpRequest();
     $request->getUrl()->setPath('/env=test/some/url');
     $app->setDebug(true);
     $app->handleRequest($request);
     $this->assertEquals('test', $app->getEnvironment());
     $this->assertEquals('/some/url', $request->getUrl()->getPath());
     $request = new HttpRequest();
     $request->getUrl()->setPath('/some/url/env=demo');
     $app->setDebug(true);
     $app->handleRequest($request);
     $this->assertEquals('demo', $app->getEnvironment());
     $this->assertEquals('/some/url', $request->getUrl()->getPath());
     $request = new HttpRequest();
     $request->getUrl()->setPath('/some/env=stage/url');
     $app->setDebug(true);
     $app->handleRequest($request);
     $this->assertEquals('stage', $app->getEnvironment());
     $this->assertEquals('/some/url', $request->getUrl()->getPath());
 }
Beispiel #10
0
 public function test_get_parameter()
 {
     $request = new HttpRequest();
     $request->getUrl()->getQuery()->set('foo', 'bar');
     $request->getData()->set('foo', 'baz');
     $request->getData()->set('yolo', 'swag');
     $this->assertEquals('bar', $request->getParameter('foo', 'default'));
     $this->assertEquals('swag', $request->getParameter('yolo', 'default'));
     $this->assertEquals('default', $request->getParameter('swag', 'default'));
 }