diff --git a/lib/Models/AmbientAirTemperature.php b/lib/Models/AmbientAirTemperature.php index 4cd3e1c..30768eb 100644 --- a/lib/Models/AmbientAirTemperature.php +++ b/lib/Models/AmbientAirTemperature.php @@ -4,6 +4,11 @@ /** * AmbientAirTemperature Model + * + * @method float getTemperatureInCelsius() + * @method \DateTime getRecordTimeStamp() + * + * @method AmbientAirTemperature setTemperatureInCelsius(float $rpm) */ class AmbientAirTemperature extends ModelAbstract { @@ -13,4 +18,33 @@ class AmbientAirTemperature extends ModelAbstract "RecordTimeStamp" ]; + /** + * @param string|\DateTime $date + * @return AmbientAirTemperature + */ + 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; + } + } diff --git a/lib/Models/Trip.php b/lib/Models/Trip.php index 5911131..058b8ea 100644 --- a/lib/Models/Trip.php +++ b/lib/Models/Trip.php @@ -2,11 +2,86 @@ namespace Automile\Sdk\Models; +use Automile\Sdk\Types\TripType; + /** * Trip Model + * + * @see TripType * * @method int getTripId() + * @method string getIMEI() + * @method string getTripStartDateTime() + * @method int getTripStartTimeZone() + * @method int getTripStartODOMeter() + * @method int getTripNumber() + * @method string getNumberOfSupportedPIDs() + * @method string getVehicleIdentificationNumber() + * @method string getVechicleProtocol() + * @method string getTripEndDateTime() + * @method int getTripEndTimeZone() + * @method int getTripEndODOMeter() + * @method string getTripStartFormattedAddress() + * @method string getTripEndFormattedAddress() + * @method string getTripStartCustomAddress() + * @method string getTripEndCustomAddress() + * @method int getTripType() + * @method string|array getTripTags() * @method int getVehicleId() + * @method float getFuelInLiters() + * @method float getTripLengthInKilometers() + * @method int getTripLengthInMinutes() + * @method int getIdleTimeInSecondsAllTrip() + * @method int getIdleTimeInSecondsFromStart() + * @method int getIdleRPMMax() + * @method string getMaxSpeed() + * @method int getMaxRPM() + * @method float getCO2EmissionInGrams() + * @method float getOdometerInKilometersAfterTripEnded() + * @method float getAverageSpeedInKilometersPerHour() + * @method float getTripStartOutsideTemperatureInCelsius() + * @method int getDriverContactId() + * @method bool getHasDrivingEvents() + * @method string getCustomCategory() + * @method bool getHideStartRoute() + * @method bool getHideEndRoute() + * + * @method int setTripId(int $tripId) + * @method string setIMEI(string $imei) + * @method string setTripStartDateTime(string $dateTime) + * @method int setTripStartTimeZone(int $timeZone) + * @method int setTripStartODOMeter(int $odometer) + * @method int setTripNumber(int $tripNumber) + * @method string setNumberOfSupportedPIDs(string $pid) + * @method string setVehicleIdentificationNumber(string $vin) + * @method string setVechicleProtocol(string $protocol) + * @method string setTripEndDateTime(string $dateTime) + * @method int setTripEndTimeZone(int $timeZone) + * @method int setTripEndODOMeter(int $odometer) + * @method string setTripStartFormattedAddress(string $address) + * @method string setTripEndFormattedAddress(string $address) + * @method string setTripStartCustomAddress(string $address) + * @method string setTripEndCustomAddress(string $address) + * @method int setTripType(int $tripType) + * @method string|array setTripTags(string $tags) + * @method int setVehicleId(int $vehicleId) + * @method float setFuelInLiters(float $liters) + * @method float setTripLengthInKilometers(float $kilometers) + * @method int setTripLengthInMinutes(int $minutes) + * @method int setIdleTimeInSecondsAllTrip(int $seconds) + * @method int setIdleTimeInSecondsFromStart(int $seconds) + * @method int setIdleRPMMax(int $rpm) + * @method string setMaxSpeed(string $speed) + * @method int setMaxRPM(int $rpm) + * @method float setCO2EmissionInGrams(float $grams) + * @method float setOdometerInKilometersAfterTripEnded(float $kilometers) + * @method float setAverageSpeedInKilometersPerHour(float $kilometers) + * @method float setTripStartOutsideTemperatureInCelsius(float $temperature) + * @method int setDriverContactId(int $contactId) + * @method bool setHasDrivingEvents(bool $events) + * @method string setCustomCategory(string $category) + * @method bool setHideStartRoute(bool $hide) + * @method bool setHideEndRoute(bool $hide) */ class Trip extends ModelAbstract { diff --git a/lib/Models/TripGeo.php b/lib/Models/TripGeo.php index 4d86ff6..9d06fa3 100644 --- a/lib/Models/TripGeo.php +++ b/lib/Models/TripGeo.php @@ -4,6 +4,19 @@ /** * TripGeo Model + * + * @method \DateTime getRecordTimeStamp() + * @method float getLatitude() + * @method float getLongitude() + * @method int getHeadingDegrees() + * @method int getNumberOfSatellites() + * @method int getHDOP() + * + * @method TripGeo setLatitude(float $lat) + * @method TripGeo setLongitude(float $lng) + * @method TripGeo setHeadingDegrees(int $degrees) + * @method TripGeo setNumberOfSatellites(int $satellites) + * @method TripGeo setHDOP(int $hdop) */ class TripGeo extends ModelAbstract { @@ -17,4 +30,33 @@ class TripGeo extends ModelAbstract "HDOP" ]; + /** + * @param string|\DateTime $date + * @return TripGeo + */ + 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; + } + } diff --git a/lib/Models/Vehicle/EngineCoolantTemperature.php b/lib/Models/Vehicle/EngineCoolantTemperature.php index 2597210..ee47f70 100644 --- a/lib/Models/Vehicle/EngineCoolantTemperature.php +++ b/lib/Models/Vehicle/EngineCoolantTemperature.php @@ -8,10 +8,9 @@ * VehicleEngineCoolantTemperature Model * * @method float getTemperatureInCelsius() - * @method string getRecordTimeStamp() + * @method \DateTime getRecordTimeStamp() * * @method EngineCoolantTemperature setTemperatureInCelsius(float $temperature) - * @method EngineCoolantTemperature setRecordTimeStamp(string $timeStamp) */ class EngineCoolantTemperature extends ModelAbstract { @@ -21,4 +20,33 @@ class EngineCoolantTemperature extends ModelAbstract "RecordTimeStamp" ]; + /** + * @param string|\DateTime $date + * @return EngineCoolantTemperature + */ + 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; + } + } diff --git a/lib/Models/Vehicle/FuelLevelInput.php b/lib/Models/Vehicle/FuelLevelInput.php index 93ea7a5..2d057f0 100644 --- a/lib/Models/Vehicle/FuelLevelInput.php +++ b/lib/Models/Vehicle/FuelLevelInput.php @@ -8,10 +8,9 @@ * VehicleFuelLevelInput Model * * @method float getFuelLevelInPercentage() - * @method string getRecordTimeStamp() + * @method \DateTime getRecordTimeStamp() * * @method FuelLevelInput setFuelLevelInPercentage(float $fuelLevel) - * @method FuelLevelInput setRecordTimeStamp(string $timeStamp) */ class FuelLevelInput extends ModelAbstract { @@ -21,4 +20,33 @@ class FuelLevelInput extends ModelAbstract "RecordTimeStamp" ]; + /** + * @param string|\DateTime $date + * @return FuelLevelInput + */ + 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; + } + } diff --git a/tests/Functional/Endpoints/TripTest.php b/tests/Functional/Endpoints/TripTest.php index de01c19..804eba8 100644 --- a/tests/Functional/Endpoints/TripTest.php +++ b/tests/Functional/Endpoints/TripTest.php @@ -2,14 +2,25 @@ namespace Automile\Sdk\Tests\Functional\Endpoints; +use Automile\Sdk\Models\AmbientAirTemperature; +use Automile\Sdk\Models\AmbientAirTemperatureRowset; use Automile\Sdk\Models\Trip; +use Automile\Sdk\Models\TripGeo; +use Automile\Sdk\Models\TripGeoRowset; +use Automile\Sdk\Models\TripPID; +use Automile\Sdk\Models\TripPIDRowset; use Automile\Sdk\Models\TripRowset; use Automile\Sdk\Models\TripStartEndGeo; +use Automile\Sdk\Models\Vehicle\EngineCoolantTemperature; +use Automile\Sdk\Models\Vehicle\EngineCoolantTemperatureRowset; +use Automile\Sdk\Models\Vehicle\FuelLevelInput; +use Automile\Sdk\Models\Vehicle\FuelLevelInputRowset; 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; +use Automile\Sdk\Types\TripType; class TripTest extends TestAbstract { @@ -48,7 +59,7 @@ public function testGetTripSpeed() $speedRowset = self::_getClient()->getTripSpeed($tripId); $this->assertInstanceOf(SpeedRowset::class, $speedRowset); - $this->greaterThan(0, count($speedRowset)); + $this->assertGreaterThan(0, count($speedRowset)); $speed = $speedRowset[0]; $this->assertInstanceOf(Speed::class, $speed); @@ -62,7 +73,7 @@ public function testGetTripRPM() $rpmRowset = self::_getClient()->getTripRPM($tripId); $this->assertInstanceOf(RPMRowset::class, $rpmRowset); - $this->greaterThan(0, count($rpmRowset)); + $this->assertGreaterThan(0, count($rpmRowset)); $rpm = $rpmRowset[0]; $this->assertInstanceOf(RPM::class, $rpm); @@ -70,4 +81,87 @@ public function testGetTripRPM() $this->assertInstanceOf(\DateTime::class, $rpm->getRecordTimeStamp()); } + public function testGetTripAmbientTemperature() + { + $tripId = self::_getSettings('trip.id'); + + $tempRowset = self::_getClient()->getTripAmbientTemperature($tripId); + $this->assertInstanceOf(AmbientAirTemperatureRowset::class, $tempRowset); + $this->assertGreaterThan(0, count($tempRowset)); + + $temp = $tempRowset[0]; + $this->assertInstanceOf(AmbientAirTemperature::class, $temp); + $this->assertInternalType('float', $temp->getTemperatureInCelsius()); + $this->assertInstanceOf(\DateTime::class, $temp->getRecordTimeStamp()); + } + + public function testGetTripFuelLevel() + { + $tripId = self::_getSettings('trip.id'); + + $fuelRowset = self::_getClient()->getTripFuelLevel($tripId); + $this->assertInstanceOf(FuelLevelInputRowset::class, $fuelRowset); + } + + public function testGetTripEngineCoolantTemperature() + { + $tripId = self::_getSettings('trip.id'); + + $coolantRowset = self::_getClient()->getTripEngineCoolantTemperature($tripId); + $this->assertInstanceOf(EngineCoolantTemperatureRowset::class, $coolantRowset); + $this->assertGreaterThan(0, count($coolantRowset)); + + $coolant = $coolantRowset[0]; + $this->assertInstanceOf(EngineCoolantTemperature::class, $coolant); + $this->assertInternalType('float', $coolant->getTemperatureInCelsius()); + $this->assertInstanceOf(\DateTime::class, $coolant->getRecordTimeStamp()); + } + + public function testGetTripPIDRaw() + { + $tripId = self::_getSettings('trip.id'); + $pidId = self::_getSettings('trip.pid_id'); + + $pidRowset = self::_getClient()->getTripPIDRaw($tripId, $pidId); + $this->assertInstanceOf(TripPIDRowset::class, $pidRowset); + } + + public function testGeoTripLatitudeLongitude() + { + $tripId = self::_getSettings('trip.id'); + + $geoRowset = self::_getClient()->geoTripLatitudeLongitude($tripId); + $this->assertInstanceOf(TripGeoRowset::class, $geoRowset); + $this->assertGreaterThan(0, count($geoRowset)); + + $geo = $geoRowset[0]; + $this->assertInstanceOf(TripGeo::class, $geo); + $this->assertInternalType('float', $geo->getLatitude()); + $this->assertInternalType('float', $geo->getLongitude()); + $this->assertInternalType('int', $geo->getHeadingDegrees()); + $this->assertInternalType('int', $geo->getNumberOfSatellites()); + $this->assertInternalType('int', $geo->getHDOP()); + $this->assertInstanceOf(\DateTime::class, $geo->getRecordTimeStamp()); + } + + public function testEdit() + { + $params = [ + 'TripId' => self::_getSettings('trip.id'), + 'TripTags' => ['tag6', 'tag5', 'tag4'], + 'TripType' => TripType::BUSINESS + ]; + + $trip = self::_getClient()->editTrip(new Trip($params)); + + $this->assertInstanceOf(Trip::class, $trip); + $this->assertEquals($params['TripId'], $trip->getTripId()); + + $trip = self::_getClient()->getTripById($params['TripId']); + $this->assertInstanceOf(Trip::class, $trip); + $this->assertEquals($params['TripId'], $trip->getTripId()); + $this->assertEquals($params['TripType'], $trip->getTripType()); + $this->assertEquals($params['TripTags'], explode(',', $trip->getTripTags())); + } + } diff --git a/tests/Functional/config.sample.json b/tests/Functional/config.sample.json index 6bd6f39..0bcde24 100644 --- a/tests/Functional/config.sample.json +++ b/tests/Functional/config.sample.json @@ -18,5 +18,9 @@ "vehicle_id": 0, "geofence_id": 0, "email": "..." + }, + "trip": { + "id": 0, + "pid_id": 0 } } \ No newline at end of file