Skip to content

Commit

Permalink
Unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerMika committed Feb 3, 2016
1 parent 8969d5b commit a8beb37
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 28 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Amadeus/Client/Session/Handler/HandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static function createHandler($handlerParams)
{
$theHandler = null;

if (!($handlerParams instanceof SessionHandlerParams) ||
!($handlerParams->authParams instanceof Client\Params\AuthParams)) {
throw new \InvalidArgumentException('Invalid parameters');
}

$handlerParams = self::loadNonceBase($handlerParams);

switch ($handlerParams->soapHeaderVersion) {
Expand Down
14 changes: 13 additions & 1 deletion src/Amadeus/Client/Session/Handler/SoapHeader4.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,24 @@ public function sendMessage($messageName, BaseWsMessage $messageBody, $messageOp
}

if ($messageOptions['asString'] === true) {
$result = $this->getLastResponse();
$result = $this->extractMessageBody($messageName, $this->getLastResponse());
}

return $result;
}

/**
* Extracts the message content from the soap envelope (i.e. everything under the soap body)
*
* @param string $messageName
* @param string $lastResponseEnvelope
* @return string
*/
protected function extractMessageBody($messageName, $lastResponseEnvelope)
{
throw new \RuntimeException(__METHOD__."() is not yet implemented");
}

/**
* Handles authentication & sessions
*
Expand Down
104 changes: 88 additions & 16 deletions tests/Amadeus/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,92 @@ public function testCanCreateClient()
$this->assertTrue($client->getStateful());
}

public function testCanCreateClientWithOverriddenSessionHandlerAndRequestCreator()
{
$par = new Params([
'sessionHandler' => $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock(),
'requestCreator' => $this->getMockBuilder('Amadeus\Client\RequestCreator\RequestCreatorInterface')->getMock()
]);

$client = new Client($par);

$this->assertInstanceOf('Amadeus\Client', $client);
}


/**
* @dataProvider dataProviderMakeMessageOptions
*/
public function testCanMakeMessageOptions($expected, $params)
{
$client = new Client($this->makeDummyParams());

$meth = self::getMethod($client, 'makeMessageOptions');

$result = $meth->invokeArgs($client, $params);

$this->assertEquals($expected, $result);
}

public function testCanSetStateful()
{
$client = new Client($this->makeDummyParams());

$current = $client->getStateful();

$this->assertTrue($current);

$client->setStateful(false);
$current = $client->getStateful();

$this->assertFalse($current);
}

public function testWillGetNullFromGetLastReqResWhenNoCallsWerMade()
{
$client = new Client($this->makeDummyParams());

$last = $client->getLastRequest();

$this->assertNull($last);

$last = $client->getLastResponse();

$this->assertNull($last);


}

public function testCanDoDummyPnrRetrieveCall()
{
$mockSessionHandler = $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock();

$messageResult = 'A dummy message result';

$expectedPnrResult = new Client\Struct\Pnr\Retrieve(Client\Struct\Pnr\Retrieve::RETR_TYPE_BY_RECLOC,'ABC123');

$mockSessionHandler
->expects($this->once())
->method('sendMessage')
->with('PNR_Retrieve', $expectedPnrResult, ['asString' => true, 'endSession' => false])
->will($this->returnValue($messageResult));

$par = new Params();
$par->sessionHandler = $mockSessionHandler;
$par->requestCreatorParams = new Params\RequestCreatorParams([
'receivedFrom' => 'some RF string',
'originatorOfficeId' => 'BRUXXXXXX'
]);

$client = new Client($par);

$response = $client->pnrRetrieve(new Client\RequestOptions\PnrRetrieveOptions(['recordLocator'=>'ABC123']));

$this->assertEquals($messageResult, $response);
}



public function dataProviderMakeMessageOptions()
{
return [
Expand Down Expand Up @@ -102,28 +188,14 @@ public function dataProviderMakeMessageOptions()
];
}

/**
* @dataProvider dataProviderMakeMessageOptions
*/
public function testCanMakeMessageOptions($expected, $params)
{
$client = new Client($this->makeDummyParams());

$meth = self::getMethod($client, 'makeMessageOptions');

$result = $meth->invokeArgs($client, $params);

$this->assertEquals($expected, $result);
}

/**
* @return Params
*/
protected function makeDummyParams()
{
return new Params([
'sessionHandlerParams' => [
'wsdl' => '/var/fake/file/path',
'wsdl' => realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . "Client" . DIRECTORY_SEPARATOR . "testfiles" . DIRECTORY_SEPARATOR . "dummywsdl.wsdl"),
'stateful' => true,
'logger' => new NullLogger(),
'authParams' => [
Expand All @@ -144,7 +216,7 @@ protected function makeDummyParams()
protected function makeClientWithMockedSessionHandler()
{
$par = new Params();
$par->sessionHandler = $this->getMockBuilder('Amadeus\Client\Session\HandlerHandlerInterface')->getMock();
$par->sessionHandler = $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock();
$par->requestCreatorParams = new Params\RequestCreatorParams([
'receivedFrom' => 'some RF string',
'originatorOfficeId' => 'BRUXXXXXX'
Expand Down

0 comments on commit a8beb37

Please sign in to comment.