Skip to content

Commit 84f4290

Browse files
committed
Tests extended, coverage increased
1 parent 110d9b4 commit 84f4290

10 files changed

Lines changed: 426 additions & 6 deletions

src/SDK/ValueObject/Factory/CalculateFlightMilesParametersFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function createFromArray(array $parameters) : CalculateFlightMiles
2323
if (array_key_exists('cabin_code', $parameters) && $parameters['cabin_code'] === 'Y') {
2424
$calculateFlightMilesParameters = $calculateFlightMilesParameters->withCabinCode();
2525
}
26-
if (array_key_exists('class_code', $parameters) && $parameters['class_code'] === 'TY') {
26+
if (array_key_exists('class_code', $parameters) && $parameters['class_code'] === 'Y') {
2727
$calculateFlightMilesParameters = $calculateFlightMilesParameters->withClassCode();
2828
}
2929
if (array_key_exists('marketingClassCode', $parameters)) {

tests/unit/Endpoint/GetAvailabilityTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function shouldGetResponseSuccessfully() : void
3535
$passengerTypeQuantity
3636
);
3737
$getAvailabilityParameters =
38-
$getAvailabilityParameters->withOriginDestinationInformation($originDestinationInformation);
38+
$getAvailabilityParameters->withOriginDestinationInformation($originDestinationInformation)
39+
->withTargetSource();
3940
$response = $this->client->getAvailability($getAvailabilityParameters);
4041
$this->assertEquals(200, $response['status']);
4142
$this->assertEquals('SUCCESS', $response['response']['status']);

tests/unit/Endpoint/GetTimeTableTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,33 @@ public function shouldFailForInvalidAirportCode() : void
7373
$this->assertEquals('SUCCESS', $response['response']['status']);
7474
$this->assertEquals('TK-0000', $response['response']['code']);
7575
}
76+
77+
/**
78+
* @test
79+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
80+
*/
81+
public function shouldFailForInvalidDurationWindowAfter() : void
82+
{
83+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
84+
$departureDateTime = new ValueObject\DepartureDateTime(
85+
new DateTimeImmutable($departureTime),
86+
'P4D',
87+
'P3D'
88+
);
89+
}
90+
91+
92+
/**
93+
* @test
94+
* @expectedException \TK\SDK\Exception\InvalidArgumentException
95+
*/
96+
public function shouldFailForInvalidDurationWindowBefore() : void
97+
{
98+
$departureTime = gmdate('Y-m-d H:i:s', strtotime('+4 days'));
99+
$departureDateTime = new ValueObject\DepartureDateTime(
100+
new DateTimeImmutable($departureTime),
101+
'P3D',
102+
'P4D'
103+
);
104+
}
76105
}

tests/unit/Factory/CalculateAwardMilesWithTaxParametersFactoryTest.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,41 @@ public function shouldReturnCalculateAwardMilesWithTaxParametersObjectSuccessful
3838
"departureDestination": "FRA",
3939
"departureDateDay": 12,
4040
"departureDateMonth": 11,
41-
"departureDateYear": 2017
41+
"departureDateYear": 2017,
42+
"ptcType": "FFY"
4243
}
4344
JSON;
4445
$parameterObject = CalculateAwardMilesWithTaxParametersFactory::createFromJson($json);
4546
$this->assertInstanceOf(CalculateAwardMilesWithTaxParameters::class, $parameterObject);
4647
$this->assertEquals(json_decode($json, true), $parameterObject->getValue());
4748
}
4849

50+
51+
/**
52+
* @test
53+
* @throws \Exception
54+
*/
55+
public function shouldReturnCalculateAwardMilesWithTaxParametersObjectSuccessfullyForArrival() : void
56+
{
57+
$year = ((int) date('Y')) +1;
58+
$json =<<<JSON
59+
{
60+
"awardType": "E",
61+
"wantMoreMiles": "T",
62+
"isOneWay": "T",
63+
"arrivalOrigin": "IST",
64+
"arrivalDestination": "FRA",
65+
"arrivalDateDay": 12,
66+
"arrivalDateMonth": 11,
67+
"arrivalDateYear": {$year}
68+
}
69+
JSON;
70+
$parameterObject = CalculateAwardMilesWithTaxParametersFactory::createFromJson($json);
71+
$this->assertInstanceOf(CalculateAwardMilesWithTaxParameters::class, $parameterObject);
72+
$this->assertEquals(json_decode($json, true), $parameterObject->getValue());
73+
}
74+
75+
4976
/**
5077
* @test
5178
*/
@@ -72,7 +99,7 @@ public function shouldFailForInvalidAwardTypeSuccessfully() : void
7299
*/
73100
public function shouldFailForInvalidIataCodeSuccessfully() : void
74101
{
75-
//$this->expectException(InvalidArgumentException::class);
102+
$this->expectException(InvalidArgumentException::class);
76103
$json =<<<JSON
77104
{
78105
"awardType": "E",
@@ -85,6 +112,28 @@ public function shouldFailForInvalidIataCodeSuccessfully() : void
85112
"departureDateYear": 2017
86113
}
87114
JSON;
88-
$parameterObject = CalculateAwardMilesWithTaxParametersFactory::createFromJson($json);
115+
CalculateAwardMilesWithTaxParametersFactory::createFromJson($json);
116+
}
117+
118+
119+
/**
120+
* @test
121+
*/
122+
public function shouldFailForInvalidJson() : void
123+
{
124+
$this->expectException(InvalidArgumentException::class);
125+
$json =<<<JSON
126+
{
127+
"awardType: "E",
128+
"wantMoreMiles": "T",
129+
"isOneWay": "T",
130+
"departureOrigin": "ICAO",
131+
"departureDestination": "FRA",
132+
"departureDateDay": 12,
133+
"departureDateMonth": 11,
134+
"departureDateYear": 2017
135+
}
136+
JSON;
137+
CalculateAwardMilesWithTaxParametersFactory::createFromJson($json);
89138
}
90139
}

tests/unit/Factory/CalculateFlightMilesParametersFactoryTest.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TK\Test\Unit\Factory;
55

6+
use TK\SDK\Exception\InvalidArgumentException;
67
use TK\SDK\ValueObject\Factory\CalculateFlightMilesParametersFactory;
78
use TK\SDK\ValueObject\CalculateFlightMilesParameters;
89

@@ -31,6 +32,8 @@ public function shouldReturnCalculateFlightMilesParameters() : void
3132
{
3233
"cabin_code": "Y",
3334
"card_type": "EP",
35+
"marketingClassCode": "TK",
36+
"marketingFlightNumber":"TK1000",
3437
"destination": "IST",
3538
"flightDate": "21.04.2017",
3639
"operatingFlightNumber": "TK1000",
@@ -42,4 +45,132 @@ public function shouldReturnCalculateFlightMilesParameters() : void
4245
$this->assertInstanceOf(CalculateFlightMilesParameters::class, $parameterObject);
4346
$this->assertEquals(json_decode($json, true), $parameterObject->getValue());
4447
}
48+
49+
/**
50+
* @test
51+
* @throws \Exception
52+
*/
53+
public function shouldReturnCalculateFlightMilesParametersWithClassCode() : void
54+
{
55+
$json =<<<JSON
56+
{
57+
"cabin_code": "Y",
58+
"card_type": "EP",
59+
"class_code": "T",
60+
"marketingClassCode": "TK",
61+
"marketingFlightNumber":"TK1000",
62+
"destination": "IST",
63+
"flightDate": "21.04.2017",
64+
"operatingFlightNumber": "TK1000",
65+
"origin": "FRA"
66+
}
67+
68+
JSON;
69+
$parameterObject = CalculateFlightMilesParametersFactory::createFromJson($json);
70+
$parameterObject->withClassCode();
71+
$this->assertInstanceOf(CalculateFlightMilesParameters::class, $parameterObject);
72+
$this->assertArrayHasKey('class_code', $parameterObject->getValue());
73+
74+
}
75+
/**
76+
* @test
77+
* @throws \Exception
78+
* @expectedException InvalidArgumentException
79+
*/
80+
public function shouldFailForInvalidCardTypesEnum() : void
81+
{
82+
$json =<<<JSON
83+
{
84+
"cabin_code": "Y",
85+
"card_type": "TT",
86+
"class_code": "Y",
87+
"marketingClassCode": "TK",
88+
"marketingFlightNumber":"TK1000",
89+
"destination": "IST",
90+
"flightDate": "21.04.2017",
91+
"operatingFlightNumber": "TK1000",
92+
"origin": "FRA"
93+
}
94+
95+
JSON;
96+
$parameterObject = CalculateFlightMilesParametersFactory::createFromJson($json);
97+
$this->assertInstanceOf(CalculateFlightMilesParameters::class, $parameterObject);
98+
$this->assertEquals(json_decode($json, true), $parameterObject->getValue());
99+
}
100+
101+
102+
103+
/**
104+
* @test
105+
* @throws \Exception
106+
* @expectedException InvalidArgumentException
107+
*/
108+
public function shouldFailForInvalidOrigin() : void
109+
{
110+
$json =<<<JSON
111+
{
112+
"cabin_code": "Y",
113+
"card_type": "TT",
114+
"class_code": "Y",
115+
"marketingClassCode": "TK",
116+
"marketingFlightNumber":"TK1000",
117+
"destination": "IST",
118+
"flightDate": "21.04.2017",
119+
"operatingFlightNumber": "TK1000",
120+
"origin": "FRAT"
121+
}
122+
123+
JSON;
124+
CalculateFlightMilesParametersFactory::createFromJson($json);
125+
}
126+
127+
128+
129+
/**
130+
* @test
131+
* @throws \Exception
132+
* @expectedException InvalidArgumentException
133+
*/
134+
public function shouldFailForInvalidDestination() : void
135+
{
136+
$json =<<<JSON
137+
{
138+
"cabin_code": "Y",
139+
"card_type": "TT",
140+
"class_code": "Y",
141+
"marketingClassCode": "TK",
142+
"marketingFlightNumber":"TK1000",
143+
"destination": "ISTT",
144+
"flightDate": "21.04.2017",
145+
"operatingFlightNumber": "TK1000",
146+
"origin": "FRA"
147+
}
148+
149+
JSON;
150+
CalculateFlightMilesParametersFactory::createFromJson($json);
151+
}
152+
153+
154+
/**
155+
* @test
156+
*/
157+
public function shouldFailForInvalidJsony() : void
158+
{
159+
$this->expectException(InvalidArgumentException::class);
160+
$json =<<<JSON
161+
{
162+
"cabin_code: "Y",
163+
"card_type": "TT",
164+
"class_code": "Y",
165+
"marketingClassCode": "TK",
166+
"marketingFlightNumber":"TK1000",
167+
"destination": "ISTT",
168+
"flightDate": "21.04.2017",
169+
"operatingFlightNumber": "TK1000",
170+
"origin": "FRA"
171+
}
172+
173+
JSON;
174+
CalculateFlightMilesParametersFactory::createFromJson($json);
175+
}
45176
}

tests/unit/Factory/GetAvailabilityParametersFactoryTest.php

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

44
namespace TK\Test\Unit\Factory;
55

6+
use TK\SDK\Exception\InvalidArgumentException;
67
use TK\SDK\ValueObject\Factory\GetAvailabilityParametersFactory;
78
use TK\SDK\ValueObject\GetAvailabilityParameters;
89

@@ -30,7 +31,105 @@ public function shouldReturnGetAvailabilityParameters() : void
3031
$json =<<<JSON
3132
{
3233
"ReducedDataIndicator":false,
33-
"RoutingType":"r",
34+
"RoutingType":"r",
35+
"TargetSource": "AWT",
36+
"PassengerTypeQuantity":[
37+
{
38+
"Code":"adult",
39+
"Quantity":1
40+
},
41+
{
42+
"Code":"child",
43+
"Quantity":1
44+
},
45+
{
46+
"Code":"infant",
47+
"Quantity":0
48+
}
49+
],
50+
"OriginDestinationInformation":[
51+
{
52+
"DepartureDateTime":{
53+
"WindowAfter":"P0D",
54+
"WindowBefore":"P0D",
55+
"Date":"14OCT"
56+
},
57+
"OriginLocation":{
58+
"LocationCode":"IST",
59+
"MultiAirportCityInd":true
60+
},
61+
"DestinationLocation":{
62+
"LocationCode":"ESB",
63+
"MultiAirportCityInd":true
64+
},
65+
"CabinPreferences":[
66+
{
67+
"Cabin":"ECONOMY"
68+
},
69+
{
70+
"Cabin":"BUSINESS"
71+
}
72+
]
73+
},
74+
{
75+
"DepartureDateTime":{
76+
"WindowAfter":"P0D",
77+
"WindowBefore":"P0D",
78+
"Date":"09JAN"
79+
},
80+
"OriginLocation":{
81+
"LocationCode":"ESB",
82+
"MultiAirportCityInd":false
83+
},
84+
"DestinationLocation":{
85+
"LocationCode":"IST",
86+
"MultiAirportCityInd":false
87+
},
88+
"CabinPreferences":[
89+
{
90+
"Cabin":"ECONOMY"
91+
},
92+
{
93+
"Cabin":"BUSINESS"
94+
}
95+
]
96+
}
97+
]
98+
}
99+
JSON;
100+
$parameterObject = GetAvailabilityParametersFactory::createFromJson($json);
101+
$this->assertInstanceOf(GetAvailabilityParameters::class, $parameterObject);
102+
$this->assertEquals(json_decode($json, true), $parameterObject->getValue());
103+
}
104+
105+
/**
106+
* @test
107+
* @throws \Exception
108+
* @expectedException InvalidArgumentException
109+
*/
110+
public function shouldFailForInvalidJson() : void
111+
{
112+
$json =<<<JSON
113+
{
114+
"ReducedDataIndicator :false,
115+
]
116+
}
117+
JSON;
118+
GetAvailabilityParametersFactory::createFromJson($json);
119+
}
120+
121+
122+
/**
123+
* @test
124+
* @throws \Exception
125+
* @expectedException InvalidArgumentException
126+
*/
127+
public function shouldFailForInvalidRoutingType() : void
128+
{
129+
$json =<<<JSON
130+
{
131+
"ReducedDataIndicator":false,
132+
"RoutingType":"z",
34133
"PassengerTypeQuantity":[
35134
{
36135
"Code":"adult",

0 commit comments

Comments
 (0)