From 4cc0406c2c9872b435f21a56d54ef642584ee6fd Mon Sep 17 00:00:00 2001 From: Marco Wansinck Date: Mon, 22 Jun 2026 22:28:59 +0200 Subject: [PATCH] feat: support VROOM 1.15 task/cost properties Add setup_per_type and service_per_type to tasks, type to vehicles and per_task_hour to costs (plus the missing per_km from 1.14). Fix vehicle step type field which was serialized as "key". Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Resource/Costs.php | 4 ++++ src/Resource/ShipmentStep.php | 10 +++++++++ src/Resource/Vehicle.php | 2 ++ src/Resource/VehicleStep.php | 2 +- tests/SerializerTest.php | 41 +++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/Resource/Costs.php b/src/Resource/Costs.php index 794c5f1..8195f09 100644 --- a/src/Resource/Costs.php +++ b/src/Resource/Costs.php @@ -9,4 +9,8 @@ class Costs public int $fixed = 0; public int $perHour = 3600; + + public int $perTaskHour = 0; + + public int $perKm = 0; } diff --git a/src/Resource/ShipmentStep.php b/src/Resource/ShipmentStep.php index 7ae55b1..5c77758 100644 --- a/src/Resource/ShipmentStep.php +++ b/src/Resource/ShipmentStep.php @@ -16,6 +16,16 @@ class ShipmentStep public int $service; + /** + * @var array + */ + public array $setupPerType; + + /** + * @var array + */ + public array $servicePerType; + /** * @var array */ diff --git a/src/Resource/Vehicle.php b/src/Resource/Vehicle.php index 51b7371..5171a95 100644 --- a/src/Resource/Vehicle.php +++ b/src/Resource/Vehicle.php @@ -33,6 +33,8 @@ final class Vehicle */ public array $skills; + public string $type; + public TimeWindowInterface $timeWindow; /** diff --git a/src/Resource/VehicleStep.php b/src/Resource/VehicleStep.php index 148b131..2beaeb1 100644 --- a/src/Resource/VehicleStep.php +++ b/src/Resource/VehicleStep.php @@ -6,7 +6,7 @@ class VehicleStep { - public string $key; + public string $type; public int $id; diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index 58e8816..df8c565 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -7,6 +7,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Exception\ExceptionInterface as SerializerException; use Webstack\Vroom\Resource\AbsoluteTimeWindow; +use Webstack\Vroom\Resource\Costs; +use Webstack\Vroom\Resource\Job; use Webstack\Vroom\Resource\Location; use Webstack\Vroom\Resource\RelativeTimeWindow; use Webstack\Vroom\Resource\Vehicle; @@ -71,4 +73,43 @@ public function testNormalizeTimeWindow(): void 14400, ], $this->serializer->normalize($relativeTimeWindow)); } + + /** + * @throws SerializerException + */ + public function testNormalizeVehicleTypeAndCosts(): void + { + $vehicle = new Vehicle(1); + $vehicle->type = 'truck'; + $vehicle->costs = new Costs(); + $vehicle->costs->perTaskHour = 1800; + $vehicle->costs->perKm = 100; + + $this->assertEquals([ + 'id' => 1, + 'costs' => [ + 'fixed' => 0, + 'per_hour' => 3600, + 'per_task_hour' => 1800, + 'per_km' => 100, + ], + 'type' => 'truck', + ], $this->serializer->normalize($vehicle)); + } + + /** + * @throws SerializerException + */ + public function testNormalizeJobPerType(): void + { + $job = new Job(999); + $job->setupPerType = ['truck' => 120, 'bike' => 300]; + $job->servicePerType = ['truck' => 60]; + + $this->assertEquals([ + 'id' => 999, + 'setup_per_type' => ['truck' => 120, 'bike' => 300], + 'service_per_type' => ['truck' => 60], + ], $this->serializer->normalize($job)); + } }