Skip to content

Commit cad8f92

Browse files
committed
More cases tested
1 parent 883582e commit cad8f92

File tree

4 files changed

+152
-20
lines changed

4 files changed

+152
-20
lines changed

tests/unit/Endpoint/GetAvailabilityTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace TK\Test\Unit\Endpoint;
55

66
use DateTimeImmutable;
7+
use TK\SDK\Exception\InvalidArgumentException;
78
use TK\SDK\ValueObject;
89

910
class GetAvailabilityTest extends EndpointAbstract
@@ -42,4 +43,48 @@ public function shouldGetResponseSuccessfully() : void
4243
$this->assertEquals('SUCCESS', $response['response']['status']);
4344
$this->assertEquals('TK-0000', $response['response']['code']);
4445
}
46+
47+
/**
48+
* @test
49+
* @expectedException InvalidArgumentException
50+
*/
51+
public function shouldFailForInvalidPassengerType() : void
52+
{
53+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
54+
$originLocation = new ValueObject\Location('IST', true);
55+
$destinationLocation = new ValueObject\Location('ESB', true);
56+
$departureDateTime = (new ValueObject\DepartureDateTime(
57+
new DateTimeImmutable($departureTime),
58+
'P3D',
59+
'P3D'
60+
))->withDateFormat('dM');
61+
(new ValueObject\OriginDestinationInformation(
62+
$departureDateTime,
63+
$originLocation,
64+
$destinationLocation
65+
))->withCabinPreferences(ValueObject\OriginDestinationInformation::CABIN_PREFERENCE_ECONOMY);
66+
(new ValueObject\PassengerTypeQuantity())
67+
->withQuantity('none', 1);
68+
}
69+
70+
/**
71+
* @test
72+
* @expectedException InvalidArgumentException
73+
*/
74+
public function shouldFailForInvalidCabinPreferences() : void
75+
{
76+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
77+
$originLocation = new ValueObject\Location('IST', true);
78+
$destinationLocation = new ValueObject\Location('ESB', true);
79+
$departureDateTime = (new ValueObject\DepartureDateTime(
80+
new DateTimeImmutable($departureTime),
81+
'P3D',
82+
'P3D'
83+
))->withDateFormat('dM');
84+
(new ValueObject\OriginDestinationInformation(
85+
$departureDateTime,
86+
$originLocation,
87+
$destinationLocation
88+
))->withCabinPreferences('N');
89+
}
4590
}

tests/unit/Endpoint/GetPortListTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TK\Test\Unit\Endpoint;
55

6+
use TK\SDK\Exception\InvalidArgumentException;
67
use TK\SDK\ValueObject;
78

89
class GetPortListTest extends EndpointAbstract
@@ -15,10 +16,32 @@ public function shouldGetResponseSuccessfully() : void
1516
$getPortListParameters = (new ValueObject\GetPortListParameters(
1617
ValueObject\GetPortListParameters::AIRLINE_CODE_TURKISH_AIRLINES
1718
))->withLanguageCode(ValueObject\GetPortListParameters::LANGUAGE_CODE_EN);
18-
1919
$response = $this->client->getPortList($getPortListParameters);
2020
$this->assertEquals(200, $response['status']);
2121
$this->assertEquals('SUCCESS', $response['response']['status']);
2222
$this->assertEquals('TK-0000', $response['response']['code']);
2323
}
24+
25+
26+
/**
27+
* @test
28+
* @expectedException InvalidArgumentException
29+
*/
30+
public function shouldFailForInvalidAirlineCode() : void
31+
{
32+
new ValueObject\GetPortListParameters(
33+
'ZZ'
34+
);
35+
}
36+
37+
/**
38+
* @test
39+
* @expectedException InvalidArgumentException
40+
*/
41+
public function shouldFailForInvalidLanguageCode() : void
42+
{
43+
(new ValueObject\GetPortListParameters(
44+
ValueObject\GetPortListParameters::AIRLINE_CODE_TURKISH_AIRLINES
45+
))->withLanguageCode('ZZZ');
46+
}
2447
}

tests/unit/Endpoint/GetTimeTableTest.php

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ public function shouldGetResponseSuccessfully() : void
4040
$this->assertEquals('TK-0000', $response['response']['code']);
4141
}
4242

43+
/**
44+
* @test
45+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
46+
*/
47+
public function shouldFailForInvalidScheduleType() : void
48+
{
49+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
50+
$originLocation = new ValueObject\Location('IST', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
51+
$destinationLocation = new ValueObject\Location('JFK', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
52+
$departureDateTime = new ValueObject\DepartureDateTime(
53+
new DateTimeImmutable($departureTime),
54+
'P3D',
55+
'P3D'
56+
);
57+
$originDestinationInformation = new ValueObject\OriginDestinationInformation(
58+
$departureDateTime,
59+
$originLocation,
60+
$destinationLocation
61+
);
62+
$airScheduleRQ = (new ValueObject\AirScheduleRQ($originDestinationInformation))
63+
->withAirlineCode(ValueObject\AirScheduleRQ::AIRLINE_TURKISH_AIRLINES)
64+
->withDirectAndNonStopOnlyInd();
65+
new ValueObject\GetTimetableParameters(
66+
$airScheduleRQ,
67+
'N',
68+
ValueObject\GetTimetableParameters::TRIP_TYPE_ONE_WAY
69+
);
70+
}
4371

4472
/**
4573
* @test
@@ -63,25 +91,29 @@ public function shouldFailForInvalidAirportCode() : void
6391
$airScheduleRQ = (new ValueObject\AirScheduleRQ($originDestinationInformation))
6492
->withAirlineCode('MK')
6593
->withDirectAndNonStopOnlyInd();
66-
$getTimetableParameters = new ValueObject\GetTimetableParameters(
94+
new ValueObject\GetTimetableParameters(
6795
$airScheduleRQ,
6896
ValueObject\GetTimetableParameters::SCHEDULE_TYPE_WEEKLY,
6997
ValueObject\GetTimetableParameters::TRIP_TYPE_ONE_WAY
7098
);
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']);
7599
}
76100

101+
/**
102+
* @test
103+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
104+
*/
105+
public function shouldFailForInvalidLocation() : void
106+
{
107+
new ValueObject\Location('ISTT', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
108+
}
77109
/**
78110
* @test
79111
* @expectedException \TK\SDK\Exception\InvalidArgumentException
80112
*/
81113
public function shouldFailForInvalidDurationWindowAfter() : void
82114
{
83115
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
84-
$departureDateTime = new ValueObject\DepartureDateTime(
116+
new ValueObject\DepartureDateTime(
85117
new DateTimeImmutable($departureTime),
86118
'P4D',
87119
'P3D'
@@ -96,10 +128,39 @@ public function shouldFailForInvalidDurationWindowAfter() : void
96128
public function shouldFailForInvalidDurationWindowBefore() : void
97129
{
98130
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
99-
$departureDateTime = new ValueObject\DepartureDateTime(
131+
new ValueObject\DepartureDateTime(
100132
new DateTimeImmutable($departureTime),
101133
'P3D',
102134
'P4D'
103135
);
104136
}
137+
138+
/**
139+
* @test
140+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
141+
*/
142+
public function shouldFailForInvalidTripType() : void
143+
{
144+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
145+
$originLocation = new ValueObject\Location('IST', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
146+
$destinationLocation = new ValueObject\Location('JFK', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
147+
$departureDateTime = new ValueObject\DepartureDateTime(
148+
new DateTimeImmutable($departureTime),
149+
'P3D',
150+
'P3D'
151+
);
152+
$originDestinationInformation = new ValueObject\OriginDestinationInformation(
153+
$departureDateTime,
154+
$originLocation,
155+
$destinationLocation
156+
);
157+
$airScheduleRQ = (new ValueObject\AirScheduleRQ($originDestinationInformation))
158+
->withAirlineCode(ValueObject\AirScheduleRQ::AIRLINE_TURKISH_AIRLINES)
159+
->withDirectAndNonStopOnlyInd();
160+
new ValueObject\GetTimetableParameters(
161+
$airScheduleRQ,
162+
ValueObject\GetTimetableParameters::SCHEDULE_TYPE_WEEKLY,
163+
'n'
164+
);
165+
}
105166
}

tests/unit/Helper/GetTimetableHelperSingleResultTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ protected function _before()
2424
->setEnvironment(getenv('TK_API_URL'), getenv('TK_API_KEY'), getenv('TK_API_SECRET'))
2525
->build();
2626
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
27-
$originLocation = new ValueObject\Location('IST', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
28-
$destinationLocation = new ValueObject\Location('BOG', ValueObject\Location::MULTIPLE_AIRPORT_TRUE);
27+
$originLocation = new ValueObject\Location('IST', ValueObject\Location::MULTIPLE_AIRPORT_FALSE);
28+
$destinationLocation = new ValueObject\Location('ESB', ValueObject\Location::MULTIPLE_AIRPORT_FALSE);
2929
$departureDateTime = new ValueObject\DepartureDateTime(
3030
new DateTimeImmutable($departureTime),
31-
'P3D',
32-
'P3D'
31+
'P0D',
32+
'P0D'
3333
);
3434
$originDestinationInformation = new ValueObject\OriginDestinationInformation(
3535
$departureDateTime,
@@ -40,10 +40,19 @@ protected function _before()
4040
->withDirectAndNonStopOnlyInd();
4141
$getTimetableParameters = new ValueObject\GetTimetableParameters(
4242
$airScheduleRQ,
43-
ValueObject\GetTimetableParameters::SCHEDULE_TYPE_WEEKLY,
43+
ValueObject\GetTimetableParameters::SCHEDULE_TYPE_DAILY,
4444
ValueObject\GetTimetableParameters::TRIP_TYPE_ONE_WAY
4545
);
4646
$this->response = $client->getTimetable($getTimetableParameters);
47+
$this->response['data']['extendedOTAAirScheduleRS']['OTA_AirScheduleRS']
48+
['OriginDestinationOptions']['OriginDestinationOption']
49+
= $this->response['data']['extendedOTAAirScheduleRS']['OTA_AirScheduleRS']
50+
['OriginDestinationOptions']['OriginDestinationOption'][0];
51+
52+
$this->response['data']['extendedOTAAirScheduleRS']['extraOTAAirScheduleRS']
53+
['extraOTAAirScheduleRSListType']['flightExtraInfo'] = $this->response['data']['extendedOTAAirScheduleRS']
54+
['extraOTAAirScheduleRS']
55+
['extraOTAAirScheduleRSListType']['flightExtraInfo'][0];
4756
}
4857

4958
protected function _after()
@@ -58,18 +67,12 @@ public function shouldGetDataSuccessfully() : void
5867
$helper = new GetTimetableHelper($this->response['data']);
5968
$flightInfo = $helper->getFlightExtraInfo();
6069
$this->assertArrayHasKey('durationType', $flightInfo);
61-
62-
$originDestinationOptions = $helper->getOriginDestinationOptions();
63-
64-
foreach ($originDestinationOptions as $originDestinationOption) {
70+
foreach ($helper->getOriginDestinationOptions() as $originDestinationOption) {
6571
$flightDetails = $helper->getFlightDetails($originDestinationOption);
66-
6772
$this->assertArrayHasKey('FlightNumber', $flightDetails);
6873
$this->assertArrayHasKey('DepartureDateTime', $flightDetails);
6974
$this->assertArrayHasKey('OperationTime', $flightDetails);
7075
$this->assertArrayHasKey('ScheduleValidEndDate', $flightDetails);
71-
72-
7376
$operationAirline = $helper->getOperationAirline($originDestinationOption);
7477
$this->assertArrayHasKey('FlightNumber', $operationAirline);
7578
$this->assertArrayHasKey('Code', $operationAirline);

0 commit comments

Comments
 (0)