Esempio n. 1
0
 /**
  * @test
  */
 public function shouldSetContentType()
 {
     //given
     $_SERVER['CONTENT_TYPE'] = 'application/json';
     //when
     ContentType::set('text/plain');
     //then
     $this->assertEquals('text/plain', ContentType::value());
 }
Esempio n. 2
0
 public static function resolve()
 {
     $accept = array_keys(RequestHeaders::accept()) ?: array('*/*');
     $supported = array('application/json' => 'application/json', 'application/xml' => 'application/xml', 'application/*' => 'application/json', 'text/html' => 'text/html', 'text/*' => 'text/html');
     $intersection = array_intersect($accept, array_keys($supported));
     if ($intersection) {
         return $supported[Arrays::first($intersection)];
     }
     return Arrays::getValue($supported, ContentType::value(), 'text/html');
 }
Esempio n. 3
0
 /**
  * @test
  */
 public function shouldReturnHtmlForUnsupportedAcceptAndNoRequestContentType()
 {
     //given
     $_SERVER['HTTP_ACCEPT'] = 'application/unsupported';
     ContentType::set(null);
     //when
     $resolved = ResponseTypeResolve::resolve();
     //then
     $this->assertEquals('text/html', $resolved);
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function shouldAcceptEmptyJson()
 {
     //given
     StreamStub::register('json');
     StreamStub::$body = '';
     ContentType::set('application/json');
     //when
     $parameters = $this->getRequestParameters('json://input');
     //then
     ArrayAssert::that($parameters)->hasSize(0);
     StreamStub::unregister();
 }
Esempio n. 5
0
 private static function _putRequestParameters($content)
 {
     if (Strings::equal(Arrays::getValue($_SERVER, 'REQUEST_METHOD'), 'PUT') && Strings::equalsIgnoreCase(ContentType::value(), 'application/x-www-form-urlencoded')) {
         parse_str($content, $parameters);
         return Arrays::toArray($parameters);
     }
     return false;
 }