Skip to content

Commit

Permalink
Trip functional tests (part 1), minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymitr committed Apr 7, 2017
1 parent e7b5530 commit 0a0716a
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Models/ModelAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __call($method, array $args)
}
break;
case 'get':
return empty($this->_properties[$property]) ? null : $this->_properties[$property];
return is_null($this->_properties[$property]) ? null : $this->_properties[$property];
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Models/TripStartEndGeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

/**
* TripStartEndGeo Model
*
* @method float getStartLatitude()
* @method float getStartLongitude()
* @method float getEndLatitude()
* @method float getEndLongitude()
*
* @method TripStartEndGeo setStartLatitude(float $lat)
* @method TripStartEndGeo setStartLongitude(float $lng)
* @method TripStartEndGeo setEndLatitude(float $lat)
* @method TripStartEndGeo setEndLongitude(float $lng)
*/
class TripStartEndGeo extends ModelAbstract
{
Expand Down
32 changes: 30 additions & 2 deletions lib/Models/Vehicle/RPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
* VehicleRPM Model
*
* @method float getRPMValue()
* @method string getRecordTimeStamp()
* @method \DateTime getRecordTimeStamp()
*
* @method RPM setRPMValue(float $rpm)
* @method RPM setRecordTimeStamp(string $timeStamp)
*/
class RPM extends ModelAbstract
{
Expand All @@ -21,4 +20,33 @@ class RPM extends ModelAbstract
"RecordTimeStamp"
];

/**
* @param string|\DateTime $date
* @return RPM
*/
public function setRecordTimeStamp($date)
{
if (!$date instanceof \DateTime) {
$date = new \DateTime($date, new \DateTimeZone('UTC'));
}
$this->_properties['RecordTimeStamp'] = $date;

return $this;
}

/**
* convert the model to an array
* @return array
*/
public function toArray()
{
$values = parent::toArray();

if (!empty($values['RecordTimeStamp'])) {
$values['RecordTimeStamp'] = $values['RecordTimeStamp']->format('c');
}

return $values;
}

}
32 changes: 30 additions & 2 deletions lib/Models/Vehicle/Speed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
* VehicleSpeed Model
*
* @method float getSpeedKmPerHour()
* @method string getRecordTimeStamp()
* @method \DateTime getRecordTimeStamp()
*
* @method Speed setSpeedKmPerHour(float $speed)
* @method Speed setRecordTimeStamp(string $timeStamp)
*/
class Speed extends ModelAbstract
{
Expand All @@ -21,4 +20,33 @@ class Speed extends ModelAbstract
"RecordTimeStamp"
];

/**
* @param string|\DateTime $date
* @return Speed
*/
public function setRecordTimeStamp($date)
{
if (!$date instanceof \DateTime) {
$date = new \DateTime($date, new \DateTimeZone('UTC'));
}
$this->_properties['RecordTimeStamp'] = $date;

return $this;
}

/**
* convert the model to an array
* @return array
*/
public function toArray()
{
$values = parent::toArray();

if (!empty($values['RecordTimeStamp'])) {
$values['RecordTimeStamp'] = $values['RecordTimeStamp']->format('c');
}

return $values;
}

}
73 changes: 73 additions & 0 deletions tests/Functional/Endpoints/TripTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Automile\Sdk\Tests\Functional\Endpoints;

use Automile\Sdk\Models\Trip;
use Automile\Sdk\Models\TripRowset;
use Automile\Sdk\Models\TripStartEndGeo;
use Automile\Sdk\Models\Vehicle\RPM;
use Automile\Sdk\Models\Vehicle\RPMRowset;
use Automile\Sdk\Models\Vehicle\Speed;
use Automile\Sdk\Models\Vehicle\SpeedRowset;
use Automile\Sdk\Tests\Functional\TestAbstract;

class TripTest extends TestAbstract
{

public function testGet()
{
$trips = self::_getClient()->getTrips(10);

$this->assertInstanceOf(TripRowset::class, $trips);
$this->assertGreaterThan(0, count($trips));
$this->assertInstanceOf(Trip::class, $trips[0]);
}

public function testGetById()
{
$tripId = self::_getSettings('trip.id');

$trip = self::_getClient()->getTripById($tripId);
$this->assertInstanceOf(Trip::class, $trip);
$this->assertEquals($tripId, $trip->getTripId());
}

public function testGetTripStartStopLatitudeLongitude()
{
$geo = self::_getClient()->getTripStartStopLatitudeLongitude(self::_getSettings('trip.id'));
$this->assertInstanceOf(TripStartEndGeo::class, $geo);
$this->assertInternalType('float', $geo->getStartLatitude());
$this->assertInternalType('float', $geo->getStartLongitude());
$this->assertInternalType('float', $geo->getEndLatitude());
$this->assertInternalType('float', $geo->getEndLongitude());
}

public function testGetTripSpeed()
{
$tripId = self::_getSettings('trip.id');

$speedRowset = self::_getClient()->getTripSpeed($tripId);
$this->assertInstanceOf(SpeedRowset::class, $speedRowset);
$this->greaterThan(0, count($speedRowset));

$speed = $speedRowset[0];
$this->assertInstanceOf(Speed::class, $speed);
$this->assertInternalType('float', $speed->getSpeedKmPerHour());
$this->assertInstanceOf(\DateTime::class, $speed->getRecordTimeStamp());
}

public function testGetTripRPM()
{
$tripId = self::_getSettings('trip.id');

$rpmRowset = self::_getClient()->getTripRPM($tripId);
$this->assertInstanceOf(RPMRowset::class, $rpmRowset);
$this->greaterThan(0, count($rpmRowset));

$rpm = $rpmRowset[0];
$this->assertInstanceOf(RPM::class, $rpm);
$this->assertInternalType('float', $rpm->getRPMValue());
$this->assertInstanceOf(\DateTime::class, $rpm->getRecordTimeStamp());
}

}

0 comments on commit 0a0716a

Please sign in to comment.