Exemplo 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());
 }
Exemplo 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');
 }
Exemplo 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);
 }
Exemplo 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();
 }
Exemplo 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;
 }