plan repo with create method
This commit is contained in:
parent
957de13e71
commit
de744c9b15
3 changed files with 47 additions and 0 deletions
10
app/Plan/CreatePlanDto.php
Normal file
10
app/Plan/CreatePlanDto.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Plan;
|
||||
|
||||
class CreatePlanDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
) {}
|
||||
}
|
||||
8
app/Plan/PlanRepository.php
Normal file
8
app/Plan/PlanRepository.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Plan;
|
||||
|
||||
interface PlanRepository
|
||||
{
|
||||
public function create(CreatePlanDto $dto): Plan;
|
||||
}
|
||||
29
tests/Fakes/FakePlanRepository.php
Normal file
29
tests/Fakes/FakePlanRepository.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Plan\CreatePlanDto;
|
||||
use App\Plan\Plan;
|
||||
use App\Plan\PlanRepository;
|
||||
|
||||
class FakePlanRepository implements PlanRepository
|
||||
{
|
||||
private array $existingPlans = [];
|
||||
|
||||
public function create(CreatePlanDto $dto): Plan
|
||||
{
|
||||
$id = $this->nextId();
|
||||
$plan = new Plan(
|
||||
id: $id,
|
||||
name: $dto->name,
|
||||
);
|
||||
$this->existingPlans[$id] = $plan;
|
||||
|
||||
return $plan;
|
||||
}
|
||||
|
||||
private function nextId(): int
|
||||
{
|
||||
return count($this->existingPlans);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue