Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FleetJourney component #4

Merged
merged 26 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7d1441
Incomplete version of FleetJourney component
senghe Nov 18, 2023
659d70f
Working on StartJourneyCommandHandler logic
MarcinKuklinskiBitBag Nov 18, 2023
5dbab34
Further implementation of starting journey process
MarcinKuklinskiBitBag Nov 19, 2023
97ee5d2
Extract FleetResolver class from StartJourneyCommandHandler
senghe Nov 19, 2023
c1bfd56
Finalizing work on StartJourneyCommandHandler
senghe Nov 20, 2023
7c49a78
Unify naming convention for repositories
senghe Nov 20, 2023
d39419b
Add logic for cancelling the journey process
senghe Nov 21, 2023
1a327cc
Completing FleetJourney component logic
senghe Nov 21, 2023
ed5fe2e
Reformat some Fleet methods
senghe Nov 23, 2023
2df0280
Validate mission eligibility on starting journey
senghe Nov 23, 2023
662ec3c
Apply ECS fixes
senghe Nov 23, 2023
b6c719e
Integrating FleetJourney component with other components
senghe Nov 24, 2023
4153360
Small refactorings and improvements
senghe Nov 24, 2023
6cdd0e5
Writing empty list of spec scenarios
senghe Nov 24, 2023
1477e82
Add ECS TypeDeclarationSpacesFixer rule; Applying ECS changes
senghe Nov 25, 2023
5639b19
Write specs for commands and events
senghe Nov 26, 2023
37b4d0a
Add specs for command handlers and event listeners of FleetJourney co…
senghe Nov 26, 2023
cb62b72
Add more specs to FleetJourney component
senghe Nov 26, 2023
4d00ef8
Fix broken specs
senghe Nov 26, 2023
52b99b1
Add SharedKernel specs
senghe Nov 26, 2023
e7f675a
Add specs for ResourceStorage EventListeners; Fix bug with checking a…
senghe Nov 30, 2023
63d7db0
Add Journey specs
senghe Dec 1, 2023
0a055b4
Add some specs to Fleet entity class
senghe Dec 2, 2023
9679aa9
Finished writing specs
MarcinKuklinskiBitBag Dec 2, 2023
f31330e
Apply ECS fixes
MarcinKuklinskiBitBag Dec 2, 2023
2a8dc4a
Fix PHPStan issues
MarcinKuklinskiBitBag Dec 2, 2023
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: 3 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
declare(strict_types=1);

use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use \PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer;
use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

Expand All @@ -20,6 +21,7 @@
$ecsConfig->rules([
NoUnusedImportsFixer::class,
PhpdocInlineTagNormalizerFixer::class,
TypeDeclarationSpacesFixer::class,
]);

// this way you can add sets - group of rules
Expand Down
1 change: 1 addition & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- src/
- spec/
- tests/
treatPhpDocTypesAsCertain: false
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use TheGame\Application\Component\BuildingConstruction\Domain\Event\BuildingConstructionHasBeenCancelledEvent;
use TheGame\Application\SharedKernel\Domain\BuildingType;
use TheGame\Application\SharedKernel\Domain\PlanetId;
use TheGame\Application\SharedKernel\Domain\ResourceRequirementsInterface;
use TheGame\Application\SharedKernel\Domain\ResourcesInterface;
use TheGame\Application\SharedKernel\EventBusInterface;
use TheGame\Application\SharedKernel\Exception\InconsistentModelException;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function it_cancels_constructing(
BuildingContextInterface $buildingBalanceContext,
EventBusInterface $eventBus,
Building $building,
ResourceRequirementsInterface $resourceRequirements,
ResourcesInterface $resourceRequirements,
): void {
$planetId = "1D632422-951F-4181-A48D-5AD654260B2B";
$buildingId = "d6949ca7-157d-4019-9267-c7a61af33b01";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use TheGame\Application\SharedKernel\Domain\BuildingType;
use TheGame\Application\SharedKernel\Domain\PlanetId;
use TheGame\Application\SharedKernel\Domain\ResourceId;
use TheGame\Application\SharedKernel\Domain\ResourceRequirementsInterface;
use TheGame\Application\SharedKernel\Domain\ResourcesInterface;
use TheGame\Application\SharedKernel\EventBusInterface;

final class StartConstructingNewBuildingCommandHandlerSpec extends ObjectBehavior
Expand All @@ -47,7 +47,7 @@ public function it_creates_building_when_building_for_the_specified_type_is_not_
Building $building,
BuildingContextInterface $buildingBalanceContext,
ResourceAvailabilityCheckerInterface $resourceAvailabilityChecker,
ResourceRequirementsInterface $resourceRequirements,
ResourcesInterface $resourceRequirements,
EventBusInterface $eventBus,
): void {
$planetId = "E7AF94C7-488C-46E4-8C44-DCD8F62B2A45";
Expand Down Expand Up @@ -101,7 +101,7 @@ public function it_throws_exception_when_storage_hasnt_enough_resources(
Building $building,
BuildingContextInterface $buildingBalanceContext,
ResourceAvailabilityCheckerInterface $resourceAvailabilityChecker,
ResourceRequirementsInterface $resourceRequirements,
ResourcesInterface $resourceRequirements,
): void {
$planetId = "E7AF94C7-488C-46E4-8C44-DCD8F62B2A45";
$resourceContextId = "52B4E60C-5CCE-4483-968E-D23D9240A18A";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use TheGame\Application\Component\ResourceStorage\Bridge\ResourceAvailabilityCheckerInterface;
use TheGame\Application\SharedKernel\Domain\BuildingType;
use TheGame\Application\SharedKernel\Domain\PlanetId;
use TheGame\Application\SharedKernel\Domain\ResourceRequirementsInterface;
use TheGame\Application\SharedKernel\Domain\ResourcesInterface;
use TheGame\Application\SharedKernel\EventBusInterface;
use TheGame\Application\SharedKernel\Exception\InconsistentModelException;

Expand Down Expand Up @@ -58,7 +58,7 @@ public function it_throws_exception_when_storage_hasnt_enough_resources(
Building $building,
BuildingContextInterface $buildingBalanceContext,
ResourceAvailabilityCheckerInterface $resourceAvailabilityChecker,
ResourceRequirementsInterface $resourceRequirements,
ResourcesInterface $resourceRequirements,
): void {
$planetId = "E7AF94C7-488C-46E4-8C44-DCD8F62B2A45";
$buildingId = "52B4E60C-5CCE-4483-968E-D23D9240A18A";
Expand Down Expand Up @@ -89,7 +89,7 @@ public function it_starts_upgrading_the_building(
Building $building,
BuildingContextInterface $buildingBalanceContext,
ResourceAvailabilityCheckerInterface $resourceAvailabilityChecker,
ResourceRequirementsInterface $resourceRequirements,
ResourcesInterface $resourceRequirements,
EventBusInterface $eventBus,
): void {
$planetId = "E7AF94C7-488C-46E4-8C44-DCD8F62B2A45";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace spec\TheGame\Application\Component\FleetJourney\Command;

use PhpSpec\ObjectBehavior;

final class CancelJourneyCommandSpec extends ObjectBehavior
{
public function let(): void
{
$fleetId = "06d98267-6399-426f-be86-b79ea570046b";
$this->beConstructedWith($fleetId);
}

public function it_has_fleet_id(): void
{
$this->getFleetId()->shouldReturn("06d98267-6399-426f-be86-b79ea570046b");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace spec\TheGame\Application\Component\FleetJourney\Command;

use PhpSpec\ObjectBehavior;

final class ReturnJourneysCommandSpec extends ObjectBehavior
{
public function let(): void
{
$userId = "0cfe1c65-2cac-4138-92bd-fac68027c39b";
$this->beConstructedWith($userId);
}

public function it_has_user_id(): void
{
$this->getUserId()->shouldReturn("0cfe1c65-2cac-4138-92bd-fac68027c39b");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

declare(strict_types=1);

namespace spec\TheGame\Application\Component\FleetJourney\Command;

use InvalidArgumentException;
use PhpSpec\ObjectBehavior;

final class StartJourneyCommandSpec extends ObjectBehavior
{
public function let(): void
{
$planetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$targetGalaxyPoint = "[1:2:3]";
$mission = "transport";
$shipsTakingJourney = [
"light-fighter" => 25,
];
$resourcesLoad = [
"5966f38b-2add-43e7-884b-64cf6569666f" => 500,
];

$this->beConstructedWith(
$planetId,
$targetGalaxyPoint,
$mission,
$shipsTakingJourney,
$resourcesLoad
);
}

public function it_has_planet_id(): void
{
$this->getPlanetId()->shouldReturn("e5835dba-aef6-4b15-9d7c-cfb177959f6d");
}

public function it_has_target_galaxy_point(): void
{
$this->getTargetGalaxyPoint()->shouldReturn("[1:2:3]");
}

public function it_has_mission_type(): void
{
$this->getMissionType()->shouldReturn("transport");
}

public function it_has_ships_taking_journey(): void
{
$this->getShipsTakingJourney()->shouldReturn([
"light-fighter" => 25,
]);
}

public function it_throws_exception_when_initializing_with_ships_taking_journey_containing_invalid_array_key(): void
{
$planetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$targetGalaxyPoint = "[1:2:3]";
$mission = "transport";
$shipsTakingJourney = [
500 => 25,
];
$resourcesLoad = [
"5966f38b-2add-43e7-884b-64cf6569666f" => 500,
];

$this->beConstructedWith(
$planetId,
$targetGalaxyPoint,
$mission,
$shipsTakingJourney,
$resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$planetId, $targetGalaxyPoint, $mission, $shipsTakingJourney, $resourcesLoad,
]);
}

public function it_throws_exception_when_initializing_with_ships_taking_journey_containing_invalid_array_value(): void
{
$planetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$targetGalaxyPoint = "[1:2:3]";
$mission = "transport";
$shipsTakingJourney = [
"light-fighter" => 25,
];
$resourcesLoad = [
"5966f38b-2add-43e7-884b-64cf6569666f" => "8bd4aaac-2d64-4b3e-be30-56be1096d9e9",
];

$this->beConstructedWith(
$planetId,
$targetGalaxyPoint,
$mission,
$shipsTakingJourney,
$resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$planetId, $targetGalaxyPoint, $mission, $shipsTakingJourney, $resourcesLoad,
]);
}

public function it_has_resources_load(): void
{
$this->getResourcesLoad()->shouldReturn([
"5966f38b-2add-43e7-884b-64cf6569666f" => 500,
]);
}

public function it_throws_exception_when_initializing_with_resources_load_containing_invalid_array_key(): void
{
$planetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$targetGalaxyPoint = "[1:2:3]";
$mission = "transport";
$shipsTakingJourney = [
"light-fighter" => 25,
];
$resourcesLoad = [
350 => 500,
];

$this->beConstructedWith(
$planetId,
$targetGalaxyPoint,
$mission,
$shipsTakingJourney,
$resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$planetId, $targetGalaxyPoint, $mission, $shipsTakingJourney, $resourcesLoad,
]);
}

public function it_throws_exception_when_initializing_with_resources_load_containing_invalid_array_value(): void
{
$planetId = "e5835dba-aef6-4b15-9d7c-cfb177959f6d";
$targetGalaxyPoint = "[1:2:3]";
$mission = "transport";
$shipsTakingJourney = [
"light-fighter" => 25,
];
$resourcesLoad = [
"5966f38b-2add-43e7-884b-64cf6569666f" => "1d9a563e-ed8a-4c5a-a918-903873f2adff",
];

$this->beConstructedWith(
$planetId,
$targetGalaxyPoint,
$mission,
$shipsTakingJourney,
$resourcesLoad
);

$this->shouldThrow(InvalidArgumentException::class)->during('__construct', [
$planetId, $targetGalaxyPoint, $mission, $shipsTakingJourney, $resourcesLoad,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace spec\TheGame\Application\Component\FleetJourney\Command;

use PhpSpec\ObjectBehavior;

final class TargetJourneysCommandSpec extends ObjectBehavior
{
public function let(): void
{
$userId = "c20f9c5c-09eb-4eba-bf7a-899507264f6a";
$this->beConstructedWith($userId);
}

public function it_has_user_id(): void
{
$this->getUserId()->shouldReturn("c20f9c5c-09eb-4eba-bf7a-899507264f6a");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace spec\TheGame\Application\Component\FleetJourney\CommandHandler;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use TheGame\Application\Component\FleetJourney\Command\CancelJourneyCommand;
use TheGame\Application\Component\FleetJourney\Domain\Entity\Fleet;
use TheGame\Application\Component\FleetJourney\Domain\Event\FleetHasCancelledJourneyEvent;
use TheGame\Application\Component\FleetJourney\Domain\FleetId;
use TheGame\Application\Component\FleetJourney\FleetRepositoryInterface;
use TheGame\Application\SharedKernel\Domain\GalaxyPointInterface;
use TheGame\Application\SharedKernel\EventBusInterface;
use TheGame\Application\SharedKernel\Exception\InconsistentModelException;

final class CancelJourneyCommandHandlerSpec extends ObjectBehavior
{
public function let(
FleetRepositoryInterface $fleetRepository,
EventBusInterface $eventBus,
): void {
$this->beConstructedWith($fleetRepository, $eventBus);
}

public function it_cancels_journey(
FleetRepositoryInterface $fleetRepository,
EventBusInterface $eventBus,
Fleet $fleet,
GalaxyPointInterface $fleetTargetPoint,
): void {
$fleetId = "f164e51d-2398-44fb-9c9d-7744681de1fe";
$fleetRepository->find(new FleetId($fleetId))->willReturn($fleet);

$fleet->cancelJourney()->shouldBeCalledOnce();

$fleet->getJourneyTargetPoint()->willReturn($fleetTargetPoint);
$fleetTargetPoint->format()->willReturn("[1:2:3]");

$eventBus->dispatch(Argument::type(FleetHasCancelledJourneyEvent::class))
->shouldBeCalledOnce();
$fleet->getResourcesLoad()->willReturn([
"3cacc092-af4a-45ca-846e-0c7060a60c43" => 500,
]);

$this->__invoke(
new CancelJourneyCommand($fleetId),
);
}

public function it_throws_exception_when_fleet_has_not_been_found(
FleetRepositoryInterface $fleetRepository,
): void {
$fleetId = "f164e51d-2398-44fb-9c9d-7744681de1fe";

$fleetRepository->find(new FleetId($fleetId))->willReturn(null);

$this->shouldThrow(InconsistentModelException::class)
->during('__invoke', [
new CancelJourneyCommand($fleetId),
]);
}
}
Loading
Loading