public function testGetTimetable() { $query = new TimetableQuery(); $query->setRoute(1)->setDeparture("123")->setDestination("456"); $provider = $this->getMockProviderReturnsTimetableParser(); $cercanias = new Cercanias($provider); $this->assertInstanceOf('\\Cercanias\\Entity\\Timetable', $cercanias->getTimetable($query)); }
* * @license MIT License */ require __DIR__ . '/..' . '/vendor/autoload.php'; use Cercanias\Cercanias; use Cercanias\Provider\TimetableQuery; use Cercanias\Provider\HorariosRenfeCom\Provider; use Cercanias\HttpAdapter\BuzzHttpAdapter; use Cercanias\Entity\Trip; use Cercanias\Entity\Train; $query = new TimetableQuery(); $query->setRoute(Provider::ROUTE_BARCELONA)->setDeparture("79600")->setDestination("71802"); // Barcelona-Passeig de Gràcia $httpAdapter = new BuzzHttpAdapter(); $provider = new Provider($httpAdapter); $cercanias = new Cercanias($provider); $timetable = $cercanias->getTimetable($query); echo "Timetable 'Barcelona': \n"; echo sprintf(" - departure: '%s'\n", $timetable->getDeparture()->getName()); echo sprintf(" - destination: '%s'\n", $timetable->getDestination()->getName()); echo sprintf(" - transfer: '%s'\n", $timetable->getTransferName()); echo sprintf(" - date: %s\n", $query->getDate()->format("Y-m-d")); $pattern = "%4s %6s %6s %6s %4s %6s\n"; echo sprintf($pattern, "LINE", "DEPART", "ARRIVE", "DEPART", "LINE", "ARRIVE"); foreach ($timetable->getTrips() as $trip) { foreach (prepareResults($trip) as $item) { echo sprintf($pattern, $item["line"], $item["departure"], $item["arrival"], $item["transfer_departure"], $item["transfer_line"], $item["transfer_arrival"]); } } function prepareResults(Trip $trip) {
<?php /** * This file is part of the Cercanias package. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @license MIT License */ require __DIR__ . '/..' . '/vendor/autoload.php'; use Cercanias\Cercanias; use Cercanias\Provider\HorariosRenfeCom\Provider; use Cercanias\HttpAdapter\CurlHttpAdapter; use Cercanias\Entity\Station; $httpAdapter = new CurlHttpAdapter(); $provider = new Provider($httpAdapter); $cercanias = new Cercanias($provider); $route = $cercanias->getRoute(Provider::ROUTE_SAN_SEBASTIAN); echo "Route 'San Sebastián': \n"; foreach ($route->getStations() as $station) { /* @var Station $station */ echo sprintf(" - [%5s] %s\n", $station->getId(), $station->getName()); } echo sprintf("results: %d\n", $route->getStations()->count());
<?php /** * This file is part of the Cercanias package. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @license MIT License */ require __DIR__ . '/..' . '/vendor/autoload.php'; use Cercanias\Cercanias; use Cercanias\Provider\HorariosRenfeCom\Provider; use Cercanias\HttpAdapter\BuzzHttpAdapter; use Cercanias\Entity\Station; $httpAdapter = new BuzzHttpAdapter(); $provider = new Provider($httpAdapter); $cercanias = new Cercanias($provider); $route = $cercanias->getRoute(Provider::ROUTE_BARCELONA); echo "Route 'Barcelona': \n"; foreach ($route->getStations() as $station) { /* @var Station $station */ echo sprintf(" - [%5s] %s\n", $station->getId(), $station->getName()); } echo sprintf("results: %d\n", $route->getStations()->count());