Responses are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return a new instance that contains the changed state.
Inheritance: implements Psr\Http\Message\ResponseInterface, use trait MessageTrait
示例#1
0
 /**
  * Test that we get a proper result when using FBS class.
  *
  * Basically a re-implementation of ExternalAuthenticationApiTest.
  */
 public function testAuthentication()
 {
     $httpclient = $this->prophesize('Reload\\Prancer\\HttpClient');
     // Invalid login.
     $httpclient->request(Argument::that(function ($request) {
         $this->assertEquals('/banana/external/v1/1234/authentication/login', $request->getUri());
         return strpos((string) $request->getBody(), 'badpass') !== false;
     }))->will(function ($args) {
         return new Response('php://memory', 403);
     });
     $httpclient = $httpclient->reveal();
     $jsonMapper = new JsonMapperSerializer(new JsonMapper());
     $fbs = new FBS('123', 'banana/', $httpclient, $jsonMapper);
     $login = new \FBS\Model\Login();
     $login->username = '******';
     $login->password = '******';
     try {
         $fbs->Authentication->login('1234', $login);
     } catch (\RuntimeException $e) {
         $this->assertEquals(403, $e->getCode());
         $this->assertEquals('invalid client credentials', $e->getMessage());
     }
     $httpclient = $this->prophesize('Reload\\Prancer\\HttpClient');
     // Valid login.
     $httpclient->request(Argument::that(function ($request) {
         return strpos((string) $request->getBody(), 'goodpass') !== false;
     }))->will(function ($args) {
         $userInfo = array('sessionKey' => md5('randomness'));
         $res = new Response(new Stream('php://memory', 'w'), 200);
         $res->getBody()->write(json_encode($userInfo));
         return $res;
     });
     $httpclient = $httpclient->reveal();
     $jsonMapper = new JsonMapperSerializer(new JsonMapper());
     $fbs = new FBS('123', 'banana/', $httpclient, $jsonMapper);
     $login->password = '******';
     $res = $fbs->Authentication->login('1234', $login);
     $this->assertInstanceOf('FBS\\Model\\ExternalAPIUserInfo', $res);
     $this->assertNotEmpty($res->sessionKey);
 }
示例#2
0
 /**
  * @param string|resource|\Psr\Http\Message\StreamableInterface $body       The response body.
  * @param integer                                               $status     The response status code.
  * @param array                                                 $headers    The response headers.
  * @param array                                                 $parameters The response parameters.
  */
 public function __construct($body = 'php://memory', $status = 200, array $headers = array(), array $parameters = array())
 {
     parent::__construct($body, $status, $headers);
     $this->parameters = $parameters;
 }
示例#3
0
 /**
  * Fake holdings.
  */
 private function getBranches($request, $vars)
 {
     $response = new Response(new Stream('php://memory', 'w'));
     $branches = array(array('branchId' => 114, 'title' => 'Gåserød Bibliotek'), array('branchId' => 113, 'title' => 'Andeby Bibliotek'), array('branchId' => 115, 'title' => 'Andelev Bibliotek'), array('branchId' => 99999999, 'title' => 'Langbortistan Bibliotek'), array('branchId' => 123, 'title' => 'Usleravnekrog Bibliotek'));
     $response->getBody()->write(json_encode($branches));
     return $response;
 }
示例#4
0
 public function testConstructorIgonoresInvalidHeaders()
 {
     $headers = [['INVALID'], 'x-invalid-null' => null, 'x-invalid-true' => true, 'x-invalid-false' => false, 'x-invalid-int' => 1, 'x-invalid-object' => (object) ['INVALID'], 'x-valid-string' => 'VALID', 'x-valid-array' => ['VALID']];
     $expected = ['x-valid-string' => ['VALID'], 'x-valid-array' => ['VALID']];
     $response = new Response('php://memory', null, $headers);
     $this->assertEquals($expected, $response->getHeaders());
 }