/**
  * @dataProvider providerForTestRequestUrl
  */
 public function testRequestUrl($command, $params, $expectedMethod, $expectedUrl)
 {
     $client = HotelClient::factory(['auth' => ['cid' => '55505', 'apiKey' => 'cbrzfta369qwyrm9t5b8y8kf'], 'defaults' => ['minorRev' => 30, 'locale' => 'en_US', 'currencyCode' => 'AUD', 'customerSessionId' => 'x', 'customerIpAddress' => 'y', 'customerUserAgent' => 'z']]);
     $mock = new Mock([new Response(200)]);
     $history = new History();
     $emitter = $client->getHttpClient()->getEmitter();
     $emitter->attach($mock);
     $emitter->attach($history);
     $command = $client->getCommand($command, $params);
     $client->execute($command);
     $request = $history->getLastRequest();
     $this->assertEquals($expectedMethod, $request->getMethod());
     $this->assertEquals('application/xml', $request->getHeader('Accept'));
     $this->assertEquals('gzip,deflate', $request->getHeader('Accept-Encoding'));
     $this->assertEquals($expectedUrl, $request->getUrl());
 }
 /**
  * Some API responses contain an EanWsError attribute instead of EanError
  */
 public function testEanErrorException_EanWsError()
 {
     $client = HotelClient::factory(['defaults' => ['cid' => '', 'apiKey' => '', 'customerIpAddress' => '', 'customerUserAgent' => '']]);
     $mock = new Mock([new Response(200, ['Content-Type' => 'application/xml'], Stream::factory('<ns2:HotelListResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/">' . '<EanWsError>' . '<itineraryId>-1</itineraryId>' . '<handling>RECOVERABLE</handling>' . '<category>DATA_VALIDATION</category>' . '<exceptionConditionId>-1</exceptionConditionId>' . '<presentationMessage>Data in this request could not be ' . 'validated: Specified city could not be resolved as valid ' . 'location.' . '</presentationMessage>' . '<verboseMessage>Data in this request could not be validated: ' . 'Specified city could not be resolved as valid location.' . '</verboseMessage>' . '<ServerInfo instance="131" timestamp="1413960307" serverTime="01:45:07.109-0500"/>' . '</EanWsError>' . '<customerSessionId>0ABAAA83-0D3B-C891-4932-697275196B14</customerSessionId>' . '</ns2:HotelListResponse>'))]);
     $client->getHttpClient()->getEmitter()->attach($mock);
     $client->getEmitter()->attach(new EanError());
     $command = $client->getCommand('GetHotelList');
     try {
         $client->execute($command);
     } catch (EanErrorException $e) {
         $this->assertEquals('RECOVERABLE', $e->getHandling());
         $this->assertEquals('DATA_VALIDATION', $e->getCategory());
         return true;
     }
     $this->fail("An EanErrorException was not thrown");
 }
 /**
  * The Content-Length: 0 header is sent with the request even though
  * the request has no body.
  */
 public function testContentLengthHeaderExists()
 {
     $client = new HotelClient(new Client(), new Description(['operations' => ['PostReservation' => ['httpMethod' => 'post']]]));
     $client->getEmitter()->attach(new ContentLength());
     $mock = new Mock([new Response(200)]);
     $history = new History();
     $client->getHttpClient()->getEmitter()->attach($mock);
     $client->getHttpClient()->getEmitter()->attach($history);
     $command = $client->getCommand('PostReservation');
     $client->execute($command);
     $request = $history->getLastRequest();
     $this->assertArrayHasKey('Content-Length', $request->getHeaders());
     $this->assertEquals('0', $request->getHeader('Content-Length'));
 }
 public function testResponseDoesNotHaveCacheControl()
 {
     $maxAge = 335;
     $matchPaths = ['/ean-services/rs/hotel/v3/info'];
     $client = new HotelClient(new Client(), new Description(['operations' => ['GetHotelList' => ['httpMethod' => 'GET', 'uri' => '/ean-services/rs/hotel/v3/list']]]));
     $client->getHttpClient()->getEmitter()->attach(new CacheControl($maxAge, $matchPaths));
     $mock = new Mock([new Response(200)]);
     $history = new History();
     $client->getHttpClient()->getEmitter()->attach($mock);
     $client->getHttpClient()->getEmitter()->attach($history);
     $command = $client->getCommand('GetHotelList');
     $client->execute($command);
     $response = $history->getLastResponse();
     $this->assertArrayNotHasKey('Cache-Control', $response->getHeaders());
 }
 /**
  * AddressInfo.postalCode only submits the first 10 characters.
  * @see http://dev.ean.com/docs/read/book_reservation#lastName
  */
 public function testAddressInfoMaxPostalCode()
 {
     $client = HotelClient::factory();
     $input = str_repeat('a', 300);
     $param = $client->getDescription()->getOperation('PostReservation')->getParam('AddressInfo')->getProperty('postalCode');
     $this->assertEquals(10, strlen($param->filter($input)), 'AddressInfo.postalCode cannot contain more than 10 characters');
 }