From 18f818bbddd64761d65a9beb0f603a110b8f8f14 Mon Sep 17 00:00:00 2001 From: Yukihiro Arisawa Date: Tue, 30 Apr 2024 00:08:37 +0900 Subject: [PATCH] add: BreedName --- src/Domain/Enum/BreedNameType.php | 24 ++++++++++++++++++++++ src/Domain/Enum/FishType.php | 10 +++++++++ src/Domain/Logic/RandomMedakaGenerator.php | 15 ++++++++++++-- src/Domain/ValueObject/Breed.php | 12 ++++++++--- tests/UseCase/AddMedakaUseCaseTest.php | 8 +++++++- 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/Domain/Enum/BreedNameType.php create mode 100644 src/Domain/Enum/FishType.php diff --git a/src/Domain/Enum/BreedNameType.php b/src/Domain/Enum/BreedNameType.php new file mode 100644 index 0000000..fc85065 --- /dev/null +++ b/src/Domain/Enum/BreedNameType.php @@ -0,0 +1,24 @@ +nicknameGenerator->generate() . 'メダカ', - new Breed('みゆき'), + $this->nicknameGenerator->generate(), + new Breed(FishType::MEDAKA, $this->pickBreedName()), 'Swim' ); } + + private function pickBreedName(): string + { + $medakaBreedNameList = BreedNameType::getBreedNameForMedaka(); + + $randomIndex = array_rand($medakaBreedNameList); + + return $medakaBreedNameList[$randomIndex]; + } } diff --git a/src/Domain/ValueObject/Breed.php b/src/Domain/ValueObject/Breed.php index 1c8a260..90c1f0b 100644 --- a/src/Domain/ValueObject/Breed.php +++ b/src/Domain/ValueObject/Breed.php @@ -7,12 +7,18 @@ class Breed { public function __construct( - private string $name + private string $fishType, + private string $breedName ) { } - public function getName(): string + public function getFishType(): string { - return $this->name; + return $this->fishType; + } + + public function getBreedName(): string + { + return $this->breedName; } } diff --git a/tests/UseCase/AddMedakaUseCaseTest.php b/tests/UseCase/AddMedakaUseCaseTest.php index c3f2346..c9c3c8d 100644 --- a/tests/UseCase/AddMedakaUseCaseTest.php +++ b/tests/UseCase/AddMedakaUseCaseTest.php @@ -6,6 +6,8 @@ namespace Iamyukihiro\Aquarium\UseCase; +use Iamyukihiro\Aquarium\Domain\Enum\BreedNameType; +use Iamyukihiro\Aquarium\Domain\Enum\FishType; use Iamyukihiro\Aquarium\Domain\Logic\RandomMedakaGenerator; use Iamyukihiro\Aquarium\Domain\Model\Fish\Medaka; use Iamyukihiro\Aquarium\Domain\Model\Tank\Tank; @@ -31,7 +33,11 @@ protected function setUp(): void public function test(): void { - $medaka = new Medaka('テストメダカ', new Breed('楊貴妃'), 'Sleeping'); + $medaka = new Medaka( + 'テストメダカ', + new Breed(FishType::MEDAKA, BreedNameType::YOUKIHI), + 'Sleeping' + ); $this->randomMedakaGeneratorP->generate()->willReturn($medaka)->shouldBeCalled(); $tank = new Tank();