Commit 846a741d authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

finish tests for the use case

parent 53265d61
Pipeline #3606 failed with stages
in 2 minutes and 7 seconds
......@@ -16,8 +16,8 @@ class APIPresenter extends BasePresenter implements Presenter
'id' => $door->getId(),
'name' => $door->getName(),
'location' => $door->getLocation(),
'created_at' => $door->getCreatedAt(),
'updated_at' => $door->getUpdatedAt(),
'created_at' => $this->formatDateTime($door->getCreatedAt()),
'updated_at' => $this->formatDateTime($door->getUpdatedAt()),
];
}
......
<?php
namespace Tests\Unit\Source\UseCases\Doors\GetDoor;
use Source\UseCases\Doors\GetDoor\Presenter;
use Source\UseCases\Doors\GetDoor\ResponseModel;
class PresenterStub implements Presenter
{
public ResponseModel $response;
protected bool $presenterCalled = false;
public function present(ResponseModel $responseModel): void
{
$this->presenterCalled = true;
$this->response = $responseModel;
}
public function wasPresenterCalled(): bool
{
return $this->presenterCalled;
}
public function getViewModel(): array
{
return [];
}
}
<?php
namespace Unit\Source\UseCases\Doors\GetDoor;
use Carbon\Carbon;
use Source\Entities\Door;
use PHPUnit\Framework\TestCase;
use Source\Entities\HashedSearchable;
use Source\UseCases\Doors\GetDoor\APIPresenter;
use Source\UseCases\Doors\GetDoor\ResponseModel;
class PresenterTest extends TestCase
{
/**
* @var \Source\UseCases\Doors\GetDoor\APIPresenter
*/
protected APIPresenter $presenter;
/**
* @var \Source\UseCases\Doors\GetDoor\ResponseModel
*/
protected ResponseModel $model;
/**
* @var array
*/
protected array $response;
public function setUp(): void
{
parent::setUp();
$this->presenter = new APIPresenter();
}
/**
* @param \Source\Entities\Door $door
*/
public function handleTest(Door $door): void
{
$this->model = new ResponseModel($door);
$this->presenter->present($this->model);
$this->response = $this->presenter->getViewModel();
}
/** @test */
public function it_formats_a_door(): void
{
$this->handleTest(new Door(
69,
'location',
'nameeee yee haw',
new HashedSearchable('how are you'),
new Carbon('2020-03-11 00:49:25'),
new Carbon('2020-03-11 00:49:29'),
));
$this->assertEquals([
'id' => 69,
'location' => 'location',
'name' => 'nameeee yee haw',
'created_at' => '2020-03-11T00:49:25+00:00',
'updated_at' => '2020-03-11T00:49:29+00:00',
], $this->response['door']);
}
}
<?php
namespace Tests\Unit\Source\UseCases\Doors\GetDoor;
use Source\Entities\Door;
use PHPUnit\Framework\TestCase;
use Source\Entities\HashedSearchable;
use Source\UseCases\Doors\GetDoor\GetDoor;
use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Doors\GetDoor\ResponseModel;
use Source\Gateways\Doors\InMemoryDoorsRepository;
class UseCaseTest extends TestCase
{
/**
* @var \Source\Gateways\Doors\InMemoryDoorsRepository
*/
protected InMemoryDoorsRepository $doors;
/**
* @var \Source\UseCases\Doors\GetDoor\GetDoor
*/
protected GetDoor $useCase;
/**
* @var \Source\UseCases\Doors\GetDoor\ResponseModel
*/
protected ResponseModel $response;
/**
* @var \Tests\Unit\Source\UseCases\Doors\GetDoor\PresenterStub
*/
protected PresenterStub $presenter;
public function setUp(): void
{
parent::setUp();
$this->doors = new InMemoryDoorsRepository();
$this->useCase = new GetDoor($this->doors);
$this->presenter = new PresenterStub();
}
/**
* @param string $doorId
* @throws EntityNotFoundException
*/
public function handleTest(string $doorId): void
{
$this->useCase->get($doorId, $this->presenter);
$this->response = $this->presenter->response;
}
/**
* @test
* @throws EntityNotFoundException
*/
public function presenter_was_called(): void
{
$this->doors->create(new Door(1, '', '', new HashedSearchable('')));
$this->handleTest('1');
$this->assertTrue($this->presenter->wasPresenterCalled());
}
/**
* @test
* @throws EntityNotFoundException
*/
public function it_throws_an_exception_when_a_user_does_not_exist(): void
{
$this->doors->create(new Door(8, '', '', new HashedSearchable('')));
$this->expectException(EntityNotFoundException::class);
$this->handleTest('adf');
}
/**
* @test
* @throws EntityNotFoundException
*/
public function it_gets_a_door(): void
{
$door = new Door(15, '', '', new HashedSearchable(''));
$this->doors->create($door);
$this->handleTest('15');
$this->assertEquals($door, $this->response->getDoor());
}
}
......@@ -39,7 +39,6 @@ class UseCaseTest extends TestCase
$this->response = $this->presenter->response;
}
/** @test */
/**
* @test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment