Skip to content

Commit

Permalink
Add specs for ResourceStorage EventListeners; Fix bug with checking a…
Browse files Browse the repository at this point in the history
…vailable resources on fleet resolver
  • Loading branch information
senghe committed Nov 30, 2023
1 parent 52b99b1 commit e7f675a
Show file tree
Hide file tree
Showing 23 changed files with 558 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function it_returns_journey_of_two_fleets(
$fleet1->getId()->willReturn(new FleetId("78131199-faa2-456f-9419-10d77ac92e13"));
$fleet1->getJourneyStartPoint()->willReturn(new GalaxyPoint(1, 2, 3));
$fleet1->getJourneyTargetPoint()->willReturn(new GalaxyPoint(2, 3, 4));
$fleet1->getJourneyReturnPoint()->willReturn(new GalaxyPoint(7,8, 9));
$fleet1->getResourcesLoad()->willReturn([
"8de65203-ad4c-4ce7-bced-cfeda9107b5d" => 300,
"42bb40d7-1d8c-4a88-86db-c10ffd68570e" => 200,
Expand All @@ -55,6 +56,7 @@ public function it_returns_journey_of_two_fleets(
$fleet2->getId()->willReturn(new FleetId("a63c152f-86d5-4ed6-8eb0-c7beb05ee517"));
$fleet2->getJourneyStartPoint()->willReturn(new GalaxyPoint(3, 4, 5));
$fleet2->getJourneyTargetPoint()->willReturn(new GalaxyPoint(4,5, 6));
$fleet2->getJourneyReturnPoint()->willReturn(new GalaxyPoint(7,8, 9));
$fleet2->getResourcesLoad()->willReturn([]);

$eventBus->dispatch(Argument::type(FleetHasReachedJourneyReturnPointEvent::class))
Expand Down Expand Up @@ -85,6 +87,7 @@ public function it_skips_fleet_when_it_has_not_returned_from_journey(
$fleet2->getId()->willReturn(new FleetId("a63c152f-86d5-4ed6-8eb0-c7beb05ee517"));
$fleet2->getJourneyStartPoint()->willReturn(new GalaxyPoint(3, 4, 5));
$fleet2->getJourneyTargetPoint()->willReturn(new GalaxyPoint(4,5, 6));
$fleet2->getJourneyReturnPoint()->willReturn(new GalaxyPoint(7,8, 9));
$fleet2->getResourcesLoad()->willReturn([]);

$eventBus->dispatch(Argument::type(FleetHasReachedJourneyReturnPointEvent::class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public function it_returns_journey_target_point(): void
{
}

public function it_throws_exception_on_returning_journey_return_point_not_being_in_journey(): void
{
}

public function it_returns_journey_return_point(): void
{
}

public function it_didnt_reach_journey_target_point_when_journey_is_null(): void
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public function let(): void
$fleetId = "e29a0a69-380d-4871-8daa-ed8e42696fba";
$startGalaxyPoint = "[1:2:3]";
$targetGalaxyPoint = "[2:3:4]";
$returnGalaxyPoint = "[5:6:7]";
$resourcesLoad = [
"e0c85daa-2b52-466d-9c7d-34063c0646d9" => 500,
];

$this->beConstructedWith($fleetId, $startGalaxyPoint, $targetGalaxyPoint, $resourcesLoad);
$this->beConstructedWith($fleetId, $startGalaxyPoint, $targetGalaxyPoint, $returnGalaxyPoint, $resourcesLoad);
}

public function it_has_fleet_id(): void
Expand All @@ -36,6 +37,11 @@ public function it_has_target_galaxy_point(): void
$this->getTargetGalaxyPoint()->shouldReturn("[2:3:4]");
}

public function it_has_return_galaxy_point(): void
{
$this->getReturnGalaxyPoint()->shouldReturn("[5:6:7]");
}

public function it_has_resources_load(): void
{
$this->getResourcesLoad()->shouldReturn([
Expand All @@ -48,16 +54,17 @@ public function it_throws_exception_when_initializing_with_resources_load_contai
$fleetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$startGalaxyPoint = "[1:2:3]";
$targetGalaxyPoint = "[2:3:4]";
$returnGalaxyPoint = "[5:6:7]";
$resourcesLoad = [
350 => 500,
];

$this->beConstructedWith(
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $resourcesLoad
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $returnGalaxyPoint, $resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $resourcesLoad,
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $returnGalaxyPoint, $resourcesLoad,
]);
}

Expand All @@ -66,16 +73,17 @@ public function it_throws_exception_when_initializing_with_resources_load_contai
$fleetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$startGalaxyPoint = "[1:2:3]";
$targetGalaxyPoint = "[2:3:4]";
$returnGalaxyPoint = "[5:6:7]";
$resourcesLoad = [
"5966f38b-2add-43e7-884b-64cf6569666f" => "1d9a563e-ed8a-4c5a-a918-903873f2adff",
];

$this->beConstructedWith(
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $resourcesLoad
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $returnGalaxyPoint, $resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $resourcesLoad,
$fleetId, $startGalaxyPoint, $targetGalaxyPoint, $returnGalaxyPoint, $resourcesLoad,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function it_creates_fleet(
)];
$stationingGalaxyPoint = new GalaxyPoint(1, 2, 3);
$resourcesLoad = new Resources();
$resourcesLoad->add(
$resourcesLoad->addResource(
new ResourceAmount(new ResourceId("8ddf9a4b-380d-4051-a1d7-9370ca4d7b3e"), 100),
);

Expand Down
Loading

0 comments on commit e7f675a

Please sign in to comment.