public function testConstructorCanAcceptAllMessageParts() { $body = new Stream('php://memory'); $status = 302; $headers = ['location' => ['http://example.com/']]; $response = new Response($body, $status, $headers); $this->assertSame($body, $response->getBody()); $this->assertEquals(302, $response->getStatusCode()); $this->assertEquals($headers, $response->getHeaders()); }
/** * 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); }
/** * 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; }