Skip to content

Commit

Permalink
Support for detecting errors in PNR_RetrieveAndDisplay messages (#2) …
Browse files Browse the repository at this point in the history
…+ Code coverage improvements
  • Loading branch information
DerMika committed Jun 21, 2016
1 parent 9079fb0 commit 7cfe1b2
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/about-get-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Soap Header 4 example:
if ($pnrResult->status === Result::STATUS_OK) {
echo "Successfully retrieved PNR, no errors in PNR found!";
echo "PNR XML string received: <pre>" . $pnrResult->responseXml . "</pre>";
}
Soap Header 2 example:
Expand Down
36 changes: 36 additions & 0 deletions src/Amadeus/Client/RequestOptions/Pnr/Segment/Hotel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Amadeus\Client\RequestOptions\Pnr\Segment;

use Amadeus\Client\RequestOptions\Pnr\Segment;

/**
* Hotel
*
* @package Amadeus\Client\RequestOptions\Pnr\Segment
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class Hotel extends Segment
{

}
13 changes: 11 additions & 2 deletions src/Amadeus/Client/ResponseHandler/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function analyzeSecuritySignOutResponse($response)
*/
protected function analyzeCommandCrypticResponse($response)
{
$ccResult = new Result($response, Result::STATUS_UNKNOWN);
$ccResult = new Result($response, Result::STATUS_UNKNOWN);
$ccResult->messages[] = new Result\NotOk(
0,
"Response handling not supported for cryptic entries"
Expand Down Expand Up @@ -258,10 +258,19 @@ protected function analyzePnrReply($response)
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'element');
}


return $analyzeResponse;
}

/**
* @param SendResult $response Pnr_RetrieveAndDisplay response
* @return Result
* @throws Exception
*/
public function analyzePnrRetrieveAndDisplayResponse($response)
{
return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
}

/**
* @param SendResult $response Queue_RemoveItem response
* @return Result
Expand Down
28 changes: 16 additions & 12 deletions src/Amadeus/Client/Struct/Offer/ConfirmHotel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ public function __construct(OfferConfirmHotelOptions $params)
}

if (!empty($params->offerReference)) {
$this->roomStayData[] = new RoomStayData();
$this->makeRoomStayData();
$this->roomStayData[0]->tattooReference = new TattooReference($params->offerReference);
}

if (!empty($params->passengers)) {
if (!isset($this->roomStayData[0])) {
$this->roomStayData[] = new RoomStayData();
}
$this->makeRoomStayData();
$this->roomStayData[0]->globalBookingInfo = new GlobalBookingInfo();

foreach ($params->passengers as $singlePass) {
Expand All @@ -106,10 +104,7 @@ public function __construct(OfferConfirmHotelOptions $params)
}

if (!empty($params->originatorId)) {
if (!isset($this->roomStayData[0])) {
$this->roomStayData[] = new RoomStayData();
}

$this->makeRoomStayData();
if(!($this->roomStayData[0]->globalBookingInfo instanceof GlobalBookingInfo)) {
$this->roomStayData[0]->globalBookingInfo = new GlobalBookingInfo();
}
Expand All @@ -118,10 +113,7 @@ public function __construct(OfferConfirmHotelOptions $params)
}

if (!empty($params->paymentType) && !empty($params->formOfPayment) && $params->paymentDetails instanceof PaymentDetailsOptions) {
if (!isset($this->roomStayData[0])) {
$this->roomStayData[] = new RoomStayData();
}

$this->makeRoomStayData();
$this->roomStayData[0]->roomList[] = new RoomList();

$this->roomStayData[0]->roomList[0]->guaranteeOrDeposit = new GuaranteeOrDeposit();
Expand All @@ -142,4 +134,16 @@ public function __construct(OfferConfirmHotelOptions $params)
}
}
}

/**
* Check for existance of RoomStayData and create if needed.
*
* @return void
*/
protected function makeRoomStayData()
{
if (!isset($this->roomStayData[0])) {
$this->roomStayData[] = new RoomStayData();
}
}
}
2 changes: 1 addition & 1 deletion src/Amadeus/Client/Struct/Pnr/AddMultiElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function createSegment($segment, &$tattooCounter)
throw new \RuntimeException('NOT YET IMPLEMENTED');
break;
default:
throw new InvalidArgumentException('Segment type ' . $segmentType . 'is not supported');
throw new InvalidArgumentException('Segment type ' . $segmentType . ' is not supported');
break;
}

Expand Down
45 changes: 45 additions & 0 deletions tests/Amadeus/Client/ResponseHandler/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ public function testCanHandleOkPnrRetrieve()
$this->assertEquals(0, count($result->messages));
}

public function testCanHandlePnrRetrieveAndDisplayErr()
{
$respHandler = new ResponseHandler\Base();

$sendResult = new SendResult();
$sendResult->responseXml = $this->getTestFile('dummyPnrRetrieveAndDisplayErrResponse.txt');

$result = $respHandler->analyzeResponse($sendResult, 'PNR_RetrieveAndDisplay');

$this->assertEquals(Result::STATUS_ERROR, $result->status);
$this->assertEquals(1, count($result->messages));
$this->assertEquals('1', $result->messages[0]->code);
$this->assertEquals("NO MATCH FOR RECORD LOCATOR", $result->messages[0]->text);
$this->assertEquals('', $result->messages[0]->level);
}

public function testCanHandlePnrRetrieveAndDisplayErr2()
{
$respHandler = new ResponseHandler\Base();

$sendResult = new SendResult();
$sendResult->responseXml = $this->getTestFile('dummyPnrRetrieveAndDisplayErr2Response.txt');

$result = $respHandler->analyzeResponse($sendResult, 'PNR_RetrieveAndDisplay');

$this->assertEquals(Result::STATUS_ERROR, $result->status);
$this->assertEquals(1, count($result->messages));
$this->assertEquals('27563', $result->messages[0]->code);
$this->assertEquals("NO OFFER", $result->messages[0]->text);
$this->assertEquals('', $result->messages[0]->level);
}

public function testCanHandleQueueRemoveItemOk()
{
$respHandler = new ResponseHandler\Base();
Expand Down Expand Up @@ -679,4 +711,17 @@ public function testCanHandleCommandCryptic()
$this->assertEquals('0', $result->messages[0]->code);
$this->assertEquals("Response handling not supported for cryptic entries", $result->messages[0]->text);
}

public function testCanGetUnknownStatusForUnknownErrorCode()
{
//Sweet sweet 100% coverage

$respHandler = new ResponseHandler\Base();

$meth = $this->getMethod('Amadeus\Client\ResponseHandler\Base', 'makeStatusFromErrorQualifier');

$result = $meth->invoke($respHandler, ['ZZZ']);

$this->assertEquals(Result::STATUS_UNKNOWN, $result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<PNR_RetrieveAndDisplayReply xmlns="http://xml.amadeus.com/PADSRR_12_2_1A">
<errorDetails>
<errorOrWarningCodeDetails>
<errorDetails>
<errorCode>27563</errorCode>
</errorDetails>
</errorOrWarningCodeDetails>
<errorWarningDescription>
<freeTextDetails>
<textSubjectQualifier>1</textSubjectQualifier>
<source>M</source>
<encoding>1</encoding>
</freeTextDetails>
<freeText>NO OFFER</freeText>
</errorWarningDescription>
</errorDetails>
</PNR_RetrieveAndDisplayReply>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<PNR_RetrieveAndDisplayReply xmlns="http://xml.amadeus.com/PADSRR_12_2_1A"><errorDetails><errorOrWarningCodeDetails><errorDetails><errorCode>1</errorCode></errorDetails></errorOrWarningCodeDetails><errorWarningDescription><freeTextDetails><textSubjectQualifier>1</textSubjectQualifier><source>M</source><encoding>1</encoding></freeTextDetails><freeText>NO MATCH FOR RECORD LOCATOR</freeText></errorWarningDescription></errorDetails></PNR_RetrieveAndDisplayReply>
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,52 @@ public function testCanDoPricePnrCallWithNoOptions()
}


/**
* Testcase where we have the Fare Basis override in the override options and also pricingsFareBasis provided
* we will test that we only have 1 pricingOptionGroup for the fare basis override.
*/
public function testCanDoPricePnrCallWithFareOverrideDuplicate()
{
$opt = new FarePricePnrWithBookingClassOptions([
'overrideOptions' => [FarePricePnrWithBookingClassOptions::OVERRIDE_FARETYPE_NEG, FarePricePnrWithBookingClassOptions::OVERRIDE_FAREBASIS],
'validatingCarrier' => 'BA',
'currencyOverride' => 'EUR',
'pricingsFareBasis' => [
new PricePnrBcFareBasis([
'fareBasisPrimaryCode' => 'QNC',
'fareBasisCode' => '469W2',
'segmentReference' => [2 => PricePnrBcFareBasis::SEGREFTYPE_SEGMENT]
])
]
]);

$message = new PricePNRWithBookingClass13($opt);

$this->assertCount(4, $message->pricingOptionGroup);

$validatingCarrierPo = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);
$validatingCarrierPo->carrierInformation = new CarrierInformation('BA');

$this->assertTrue($this->assertArrayContainsSameObject($message->pricingOptionGroup, $validatingCarrierPo));

$currencyOverridePo = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
$currencyOverridePo->currency = new Currency('EUR');

$this->assertTrue($this->assertArrayContainsSameObject($message->pricingOptionGroup, $currencyOverridePo));

$fareBasisOverridePo = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
$fareBasisOverridePo->optionDetail = new OptionDetail();
$fareBasisOverridePo->optionDetail->criteriaDetails[] = new CriteriaDetails('QNC469W2');
$fareBasisOverridePo->paxSegTstReference = new PaxSegTstReference([2 => PricePnrBcFareBasis::SEGREFTYPE_SEGMENT]);

$this->assertTrue($this->assertArrayContainsSameObject($message->pricingOptionGroup, $fareBasisOverridePo));

$negofarePo = new PricingOptionGroup(PricingOptionKey::OPTION_NEGOTIATED_FARES);

$this->assertTrue($this->assertArrayContainsSameObject($message->pricingOptionGroup, $negofarePo));
}


/**
* @param $theArray
* @param $theObject
Expand Down
44 changes: 44 additions & 0 deletions tests/Amadeus/Client/Struct/Offer/ConfirmHotel/AgeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Test\Amadeus\Client\Struct\Offer\ConfirmHotel;

use Amadeus\Client\Struct\Offer\ConfirmHotel\Age;
use Amadeus\Client\Struct\Offer\ConfirmHotel\QuantityDetails;
use Test\Amadeus\BaseTestCase;

/**
* AgeTest
*
* @package Test\Amadeus\Client\Struct\Offer\ConfirmHotel
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class AgeTest extends BaseTestCase
{
public function testCanCreate()
{
$age = new Age('25');

$this->assertEquals('25', $age->quantityDetails->value);
$this->assertEquals(QuantityDetails::QUAL_AGE, $age->quantityDetails->qualifier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Test\Amadeus\Client\Struct\Offer\ConfirmHotel;

use Amadeus\Client\Struct\Offer\ConfirmHotel\HotelProductReference;
use Amadeus\Client\Struct\Offer\ConfirmHotel\ReferenceDetails;
use Test\Amadeus\BaseTestCase;

/**
* HotelProductReferenceTest
*
* @package Test\Amadeus\Client\Struct\Offer\ConfirmHotel
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class HotelProductReferenceTest extends BaseTestCase
{
public function testCanCreate()
{
$element = new HotelProductReference();

$this->assertEquals(ReferenceDetails::TYPE_BOOKING_CODE, $element->referenceDetails->type);
$this->assertNull($element->referenceDetails->value);
}
}
Loading

0 comments on commit 7cfe1b2

Please sign in to comment.