connector->createRequest( 'https://localhost:8888/path-here', 'POST', ['query' => ['q' => '1']] ); $this->assertInstanceOf('GuzzleHttp\Message\RequestInterface', $request); $this->assertEquals('POST', $request->getMethod()); $this->assertEquals( 'https://localhost:8888/path-here?q=1', $request->getUrl() ); $this->assertEquals(self::MERCHANT_ID, $request->getConfig()['auth'][0]); $this->assertEquals(self::SHARED_SECRET, $request->getConfig()['auth'][1]); $this->assertEquals( strval($this->connector->getUserAgent()), $request->getHeader('User-Agent') ); } /** * Make sure that the request sent returns an response. * * @return void */ public function testSend() { $response = new Response(200); $this->mock->addResponse($response); $request = $this->connector->createRequest('http://somewhere/path', 'POST'); $this->assertSame($response, $this->connector->send($request)); } /** * Make sure that an API error response throws a connector exception. * * @return void */ public function testSendError() { $json = << 'application/json'], Stream::factory($json) ); $this->mock->addResponse($response); $this->setExpectedException( 'Klarna\Rest\Transport\Exception\ConnectorException', 'ERR_1: msg1, msg2 (#cid_1)' ); $request = $this->connector->createRequest('http://somewhere/path', 'POST'); $this->connector->send($request); } /** * Make sure that an error response throws an exception. * * @return void */ public function testSendGuzzleError() { $response = new Response(404); $this->mock->addResponse($response); $this->setExpectedException('GuzzleHttp\Exception\ClientException'); $request = $this->connector->createRequest('http://somewhere/path', 'POST'); $this->connector->send($request); } /** * Make sure that the factory method creates a connector as expected. * * @return void */ public function testCreate() { $userAgent = $this->getMockBuilder('Klarna\Rest\Transport\UserAgent') ->getMock(); $connector = Connector::create( self::MERCHANT_ID, self::SHARED_SECRET, self::BASE_URL, $userAgent ); $this->assertSame($userAgent, $connector->getUserAgent()); $this->assertEquals(self::BASE_URL, $connector->getClient()->getBaseUrl()); } }