Skip to content

Commit fac4282

Browse files
committed
Client tests extended
1 parent 229f303 commit fac4282

3 files changed

Lines changed: 109 additions & 1 deletion

File tree

tests/unit/ClientTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TK\Test\Unit;
5+
6+
use TK\SDK\ValueObject\Factory\RetrieveReservationDetailParametersFactory;
7+
use TK\SDK\ClientBuilder;
8+
use Dotenv;
9+
10+
class ClientTest extends \Codeception\Test\Unit
11+
{
12+
/**
13+
* @var \UnitTester
14+
*/
15+
protected $tester;
16+
17+
private $client;
18+
19+
protected function _before()
20+
{
21+
if (file_exists(__DIR__.'/../../.env')) {
22+
$dotFile = __DIR__.'/../..';
23+
$dotenv = new Dotenv\Dotenv($dotFile);
24+
$dotenv->load();
25+
}
26+
$this->client = ClientBuilder::create()
27+
->setEnvironment(getenv('TK_API_URL'), getenv('TK_API_KEY'), getenv('TK_API_SECRET'))
28+
->setLogger()
29+
->build();
30+
}
31+
32+
protected function _after()
33+
{
34+
}
35+
36+
/**
37+
* @test
38+
* @expectedException \TK\SDK\Exception\RequestException
39+
*/
40+
public function shouldThrowExceptionForFailure() : void
41+
{
42+
43+
$json =<<<JSON
44+
{
45+
"UniqueId": "INVALID_ID",
46+
"Surname": "INVALID_SURNAME"
47+
}
48+
JSON;
49+
$parameterObject = RetrieveReservationDetailParametersFactory::createFromJson($json);
50+
$this->client->retrieveReservationDetail($parameterObject);
51+
}
52+
53+
/**
54+
* @test
55+
* @expectedException \TK\SDK\Exception\BadMethodCallException
56+
*/
57+
public function shouldThrowExceptionForInvalidEndpoint() : void
58+
{
59+
$this->client->invalidEndpoint([]);
60+
}
61+
62+
/**
63+
* @test
64+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
65+
*/
66+
public function shouldThrowExceptionForInvalidArgument() : void
67+
{
68+
$this->client->retrieveReservationDetail([]);
69+
}
70+
}

tests/unit/Endpoint/EndpointAbstract.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use Dotenv;
77
use TK\SDK\ClientBuilder;
8+
use Monolog\Logger;
9+
use Monolog\Handler\NullHandler;
810

911
abstract class EndpointAbstract extends \Codeception\Test\Unit
1012
{
@@ -17,14 +19,16 @@ abstract class EndpointAbstract extends \Codeception\Test\Unit
1719

1820
protected function _before()
1921
{
20-
ini_set('xdebug.overload_var_dump', '0');
2122
if (file_exists(__DIR__.'/../../../.env')) {
2223
$dotFile = __DIR__.'/../../..';
2324
$dotenv = new Dotenv\Dotenv($dotFile);
2425
$dotenv->load();
2526
}
27+
$logger = new Logger('my_logger');
28+
$logger->pushHandler(new NullHandler());
2629
$this->client = ClientBuilder::create()
2730
->setEnvironment(getenv('TK_API_URL'), getenv('TK_API_KEY'), getenv('TK_API_SECRET'))
31+
->setLogger($logger)
2832
->build();
2933
}
3034

tests/unit/Endpoint/GetTimeTableTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,38 @@ public function shouldGetResponseSuccessfully() : void
3939
$this->assertEquals('SUCCESS', $response['response']['status']);
4040
$this->assertEquals('TK-0000', $response['response']['code']);
4141
}
42+
43+
44+
/**
45+
* @test
46+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
47+
*/
48+
public function shouldFailForInvalidAirportCode() : void
49+
{
50+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
51+
$originLocation = new ValueObject\Location('IST', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
52+
$destinationLocation = new ValueObject\Location('JFK', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
53+
$departureDateTime = new ValueObject\DepartureDateTime(
54+
new DateTimeImmutable($departureTime),
55+
'P3D',
56+
'P3D'
57+
);
58+
$originDestinationInformation = new ValueObject\OriginDestinationInformation(
59+
$departureDateTime,
60+
$originLocation,
61+
$destinationLocation
62+
);
63+
$airScheduleRQ = (new ValueObject\AirScheduleRQ($originDestinationInformation))
64+
->withAirlineCode('MK')
65+
->withDirectAndNonStopOnlyInd();
66+
$getTimetableParameters = new ValueObject\GetTimetableParameters(
67+
$airScheduleRQ,
68+
ValueObject\GetTimetableParameters::SCHEDULE_TYPE_WEEKLY,
69+
ValueObject\GetTimetableParameters::TRIP_TYPE_ONE_WAY
70+
);
71+
$response = $this->client->getTimetable($getTimetableParameters);
72+
$this->assertEquals(200, $response['status']);
73+
$this->assertEquals('SUCCESS', $response['response']['status']);
74+
$this->assertEquals('TK-0000', $response['response']['code']);
75+
}
4276
}

0 commit comments

Comments
 (0)