Esempio n. 1
0
 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));
 }
Esempio n. 2
0
 /**
  * @dataProvider getGenerateTimetableUrlProvider
  */
 public function testGenerateTimetableUrl($expectedUrl, $values)
 {
     $query = new TimetableQuery();
     $query->setRoute($values["route"])->setDeparture($values["from"])->setDestination($values["to"]);
     if ($values["date"]) {
         $query->setDate($values["date"]);
     }
     $provider = new Provider($this->getMockAdapter($this->never()));
     $this->assertEquals($expectedUrl, $provider->generateTimetableUrl($query));
 }
/**
 * 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\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) {
<?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\HttpAdapter\CurlHttpAdapter;
use Cercanias\Provider\HorariosRenfeCom\Provider;
use Cercanias\Provider\TimetableQuery;
use Cercanias\Cercanias;
use Cercanias\Entity\Trip;
$query = new TimetableQuery();
$query->setRoute(Provider::ROUTE_SAN_SEBASTIAN)->setDeparture("11305")->setDestination("11600")->setDate(new \DateTime("now"));
$httpAdapter = new CurlHttpAdapter();
$provider = new Provider($httpAdapter);
$cercanias = new Cercanias($provider);
$timetable = $cercanias->getTimetable($query);
echo "Timetable 'San Sebastián': \n";
echo sprintf(" - departure:     '%s'\n", $timetable->getDeparture()->getName());
echo sprintf(" - destination:   '%s'\n", $timetable->getDestination()->getName());
echo sprintf(" - date:          %s\n", $query->getDate()->format("Y-m-d"));
$pattern = "%4s  %6s  %6s  %4s\n";
echo sprintf($pattern, "LINE", "DEPART", "ARRIVE", "TIME");
foreach ($timetable->getTrips() as $trip) {
    /* @var Trip $trip*/
    echo sprintf($pattern, $trip->getDepartureTrain()->getLine(), $trip->getDepartureTrain()->getDepartureTime()->format("H:i"), $trip->getDepartureTrain()->getArrivalTime()->format("H:i"), $trip->getDepartureTrain()->getDuration()->format("%h:%i"));
}
Esempio n. 5
0
 public function testIsValidWithConcatenatedSetters()
 {
     $query = new TimetableQuery();
     $query->setRoute(1)->setDeparture(123)->setDestination(456)->setDate(new \DateTime("now"));
     $this->assertTrue($query->isValid());
 }