|
| 1 | +<?php namespace Helper; |
| 2 | + |
| 3 | +use TK\SDK\ClientBuilder; |
| 4 | +use DateTimeImmutable; |
| 5 | +use TK\SDK\Helper\GetTimetableHelper; |
| 6 | +use TK\SDK\ValueObject; |
| 7 | +use Dotenv; |
| 8 | + |
| 9 | +class GetTimetableHelperSingleResultTest extends \Codeception\Test\Unit |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var \UnitTester |
| 13 | + */ |
| 14 | + protected $tester; |
| 15 | + private $response; |
| 16 | + |
| 17 | + protected function _before() |
| 18 | + { |
| 19 | + if (file_exists(__DIR__.'/../../../.env')) { |
| 20 | + $dotenv = new Dotenv\Dotenv(__DIR__ . '/../../..'); |
| 21 | + $dotenv->load(); |
| 22 | + } |
| 23 | + $client = ClientBuilder::create() |
| 24 | + ->setEnvironment(getenv('TK_API_URL'), getenv('TK_API_KEY'), getenv('TK_API_SECRET')) |
| 25 | + ->build(); |
| 26 | + $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); |
| 29 | + $departureDateTime = new ValueObject\DepartureDateTime( |
| 30 | + new DateTimeImmutable($departureTime), |
| 31 | + 'P3D', |
| 32 | + 'P3D' |
| 33 | + ); |
| 34 | + $originDestinationInformation = new ValueObject\OriginDestinationInformation( |
| 35 | + $departureDateTime, |
| 36 | + $originLocation, |
| 37 | + $destinationLocation |
| 38 | + ); |
| 39 | + $airScheduleRQ = (new ValueObject\AirScheduleRQ($originDestinationInformation)) |
| 40 | + ->withDirectAndNonStopOnlyInd(); |
| 41 | + $getTimetableParameters = new ValueObject\GetTimetableParameters( |
| 42 | + $airScheduleRQ, |
| 43 | + ValueObject\GetTimetableParameters::SCHEDULE_TYPE_WEEKLY, |
| 44 | + ValueObject\GetTimetableParameters::TRIP_TYPE_ONE_WAY |
| 45 | + ); |
| 46 | + $this->response = $client->getTimetable($getTimetableParameters); |
| 47 | + } |
| 48 | + |
| 49 | + protected function _after() |
| 50 | + { |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @test |
| 55 | + */ |
| 56 | + public function shouldGetDataSuccessfully() : void |
| 57 | + { |
| 58 | + $helper = new GetTimetableHelper($this->response['data']); |
| 59 | + $flightInfo = $helper->getFlightExtraInfo(); |
| 60 | + $this->assertArrayHasKey('durationType', $flightInfo); |
| 61 | + |
| 62 | + $originDestinationOptions = $helper->getOriginDestinationOptions(); |
| 63 | + |
| 64 | + foreach ($originDestinationOptions as $originDestinationOption) { |
| 65 | + $flightDetails = $helper->getFlightDetails($originDestinationOption); |
| 66 | + |
| 67 | + $this->assertArrayHasKey('FlightNumber', $flightDetails); |
| 68 | + $this->assertArrayHasKey('DepartureDateTime', $flightDetails); |
| 69 | + $this->assertArrayHasKey('OperationTime', $flightDetails); |
| 70 | + $this->assertArrayHasKey('ScheduleValidEndDate', $flightDetails); |
| 71 | + |
| 72 | + |
| 73 | + $operationAirline = $helper->getOperationAirline($originDestinationOption); |
| 74 | + $this->assertArrayHasKey('FlightNumber', $operationAirline); |
| 75 | + $this->assertArrayHasKey('Code', $operationAirline); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments