test create plan with request
This commit is contained in:
parent
de744c9b15
commit
9f29b9b94e
3 changed files with 52 additions and 0 deletions
21
app/Plan/UseCases/CreatePlan.php
Normal file
21
app/Plan/UseCases/CreatePlan.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Plan\UseCases;
|
||||||
|
|
||||||
|
use App\Plan\CreatePlanDto;
|
||||||
|
use App\Plan\Plan;
|
||||||
|
use App\Plan\PlanRepository;
|
||||||
|
|
||||||
|
class CreatePlan
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private PlanRepository $planRepo,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function execute(CreatePlanRequest $request): Plan
|
||||||
|
{
|
||||||
|
return $this->planRepo->create(new CreatePlanDto(
|
||||||
|
name: $request->name,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
10
app/Plan/UseCases/CreatePlanRequest.php
Normal file
10
app/Plan/UseCases/CreatePlanRequest.php
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Plan\UseCases;
|
||||||
|
|
||||||
|
class CreatePlanRequest
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $name,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
21
tests/Unit/Plan/UseCases/CreatePlanTest.php
Normal file
21
tests/Unit/Plan/UseCases/CreatePlanTest.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Plan\UseCases;
|
||||||
|
|
||||||
|
use App\Plan\UseCases\CreatePlan;
|
||||||
|
use App\Plan\UseCases\CreatePlanRequest;
|
||||||
|
use Tests\Fakes\FakePlanRepository;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class CreatePlanTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_create_plan(): void
|
||||||
|
{
|
||||||
|
$planRepo = new FakePlanRepository;
|
||||||
|
$useCase = new CreatePlan($planRepo);
|
||||||
|
$plan = $useCase->execute(new CreatePlanRequest(
|
||||||
|
name: 'testPlan',
|
||||||
|
));
|
||||||
|
$this->assertEquals('testPlan', $plan->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue