Beispiel #1
0
 /**
  * @covers OAuth2\Response::content_type()
  * @covers OAuth2\Response::parse()
  */
 public function testParseResponse()
 {
     // parses application/x-www-form-urlencoded body
     $headers = array('Content-Type' => 'application/x-www-form-urlencoded');
     $body = 'foo=bar&answer=42';
     $this->response = new \OAuth2\Response(new \GuzzleHttp\Message\Response(200, $headers, \GuzzleHttp\Stream\Stream::factory($body)));
     $parsedResponse = $this->response->parse();
     $this->assertEquals(2, count(array_keys($parsedResponse)));
     $this->assertEquals('bar', $parsedResponse['foo']);
     $this->assertEquals(42, $parsedResponse['answer']);
     // parses application/json body
     $headers = array('Content-Type' => 'application/json');
     $body = json_encode(array('foo' => 'bar', 'answer' => 42));
     $this->response = new \OAuth2\Response(new \GuzzleHttp\Message\Response(200, $headers, \GuzzleHttp\Stream\Stream::factory($body)));
     $parsedResponse = $this->response->parse();
     $this->assertEquals(2, count(array_keys($parsedResponse)));
     $this->assertEquals('bar', $parsedResponse['foo']);
     $this->assertEquals(42, $parsedResponse['answer']);
     // doesn't try to parse other content-types
     $headers = array('Content-Type' => 'text/html');
     $body = '<!DOCTYPE html><html><head></head><body></body></html>';
     $this->response = new \OAuth2\Response(new \GuzzleHttp\Message\Response(200, $headers, \GuzzleHttp\Stream\Stream::factory($body)));
     $this->assertNull($this->response->parse());
 }