Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Resource/Costs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ class Costs
public int $fixed = 0;

public int $perHour = 3600;

public int $perTaskHour = 0;

public int $perKm = 0;
}
10 changes: 10 additions & 0 deletions src/Resource/ShipmentStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class ShipmentStep

public int $service;

/**
* @var array<string, int>
*/
public array $setupPerType;

/**
* @var array<string, int>
*/
public array $servicePerType;

/**
* @var array<TimeWindowInterface>
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Resource/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ final class Vehicle
*/
public array $skills;

public string $type;

public TimeWindowInterface $timeWindow;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/VehicleStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class VehicleStep
{
public string $key;
public string $type;

public int $id;

Expand Down
41 changes: 41 additions & 0 deletions tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}