public function getRunsInADay(RequestRuns $requestRuns) { $service_type = 'consultarCorridas'; $formattedDateOfRun = $requestRuns->getDateOfRun()->format('c'); $service_params = array('in0' => $requestRuns->getOriginId(), 'in1' => $requestRuns->getDestinationId(), 'in2' => $formattedDateOfRun, 'in3' => $this->usuario, 'in4' => $this->password); $soap_param = array('ventaService' => $service_params); $configMaxSocketTimeout = ini_get('default_socket_timeout'); try { ini_set('default_socket_timeout', $this->maxSocketTimeout); $soap_response = $this->callSoapServiceByType($service_type, $soap_param); ini_set('default_socket_timeout', $configMaxSocketTimeout); } catch (\Exception $e) { ini_set('default_socket_timeout', $configMaxSocketTimeout); throw new TimeoutException('There was no response from the Booking Engine'); } if (isset($this->logger)) { $this->logger->addNotice(print_r($soap_response, true)); } if (!isset($soap_response->out->Corrida)) { return new ResponseRuns(); } $corrida = $soap_response->out->Corrida; $response = $this->normalizeResponseToRun($corrida); return $response; }
public function test_if_normalize_response_to_run_returns_a_valid_runs_object_one_run_response() { $dummyresponse1 = self::createDummyConsultaCorridasResponseObject(); $dummyresponse = (object) array('out' => (object) array('Corrida' => $dummyresponse1->out->Corrida[0])); $this->fakeSoapClient->setResponse($dummyresponse); $requestRuns = new RequestRuns(); $requestRuns->setOriginId(1886); $requestRuns->setDestinationId(2219); $tomorrow = new \DateTime('tomorrow'); $requestRuns->setDateOfRun($tomorrow); $runs = $this->client->getRunsInADay($requestRuns); $this->assertGreaterThan(0, count($runs)); $this->assertInstanceOf('Transpais\\Type\\Run', $runs[0]); $this->assertInstanceOf('\\DateTime', $runs[0]->getDateOfRun()); $this->assertInstanceOf('\\DateTime', $runs[0]->getDateOfArrival()); $this->assertInstanceOf('\\DateTime', $runs[0]->getDateOfDeparture()); }