Skip to content

Commit

Permalink
add: BreedName
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukihiro Arisawa committed Apr 29, 2024
1 parent 39c9529 commit 18f818b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
24 changes: 24 additions & 0 deletions src/Domain/Enum/BreedNameType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Iamyukihiro\Aquarium\Domain\Enum;

class BreedNameType
{
public const HI_MEDAKA = '緋目高';
public const MIYUKI = 'みゆき';
public const YOUKIHI = '楊貴妃';
public const OROCHI = 'オロチ';

/** @return string[] */
public static function getBreedNameForMedaka(): array
{
return [
self::HI_MEDAKA,
self::MIYUKI,
self::YOUKIHI,
self::OROCHI,
];
}
}
10 changes: 10 additions & 0 deletions src/Domain/Enum/FishType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Iamyukihiro\Aquarium\Domain\Enum;

class FishType
{
public const MEDAKA = 'メダカ';
}
15 changes: 13 additions & 2 deletions src/Domain/Logic/RandomMedakaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Iamyukihiro\Aquarium\Domain\Logic;

use Iamyukihiro\Aquarium\Domain\Enum\BreedNameType;
use Iamyukihiro\Aquarium\Domain\Enum\FishType;
use Iamyukihiro\Aquarium\Domain\Model\Fish\Medaka;
use Iamyukihiro\Aquarium\Domain\ValueObject\Breed;

Expand All @@ -20,9 +22,18 @@ public function __construct(
public function generate(): Medaka
{
return new Medaka(
$this->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];
}
}
12 changes: 9 additions & 3 deletions src/Domain/ValueObject/Breed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 7 additions & 1 deletion tests/UseCase/AddMedakaUseCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 18f818b

Please sign in to comment.