add company Name to Carrier
This commit is contained in:
parent
5cd4d3ad3f
commit
9043b93555
6 changed files with 31 additions and 7 deletions
|
|
@ -7,6 +7,7 @@ class Carrier
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ?int $id,
|
private ?int $id,
|
||||||
private string $email,
|
private string $email,
|
||||||
|
private string $companyName,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
|
@ -23,4 +24,9 @@ class Carrier
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCompanyName(): string
|
||||||
|
{
|
||||||
|
return $this->companyName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,11 @@ class CreateCarrier
|
||||||
|
|
||||||
public function execute(): Carrier
|
public function execute(): Carrier
|
||||||
{
|
{
|
||||||
$carrier = new Carrier(null, $this->dto->email);
|
$carrier = new Carrier(
|
||||||
|
null,
|
||||||
|
$this->dto->email,
|
||||||
|
$this->dto->companyName
|
||||||
|
);
|
||||||
|
|
||||||
return $this->carrierRepo->save($carrier);
|
return $this->carrierRepo->save($carrier);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ class CreateCarrierRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $email,
|
public string $email,
|
||||||
|
public string $companyName,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,11 @@ class FakeCarrierRepository implements CarrierRepository
|
||||||
{
|
{
|
||||||
foreach ($this->existingCarriers as $carrier) {
|
foreach ($this->existingCarriers as $carrier) {
|
||||||
if ($carrier->getId() === $id) {
|
if ($carrier->getId() === $id) {
|
||||||
return new Carrier($id, $carrier->getEmail());
|
return new Carrier(
|
||||||
|
$id,
|
||||||
|
$carrier->getEmail(),
|
||||||
|
$carrier->getCompanyName(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +33,11 @@ class FakeCarrierRepository implements CarrierRepository
|
||||||
}
|
}
|
||||||
$this->existingCarriers[$id] = $carrier;
|
$this->existingCarriers[$id] = $carrier;
|
||||||
|
|
||||||
return new Carrier($id, $carrier->getEmail());
|
return new Carrier(
|
||||||
|
$id,
|
||||||
|
$carrier->getEmail(),
|
||||||
|
$carrier->getCompanyName(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function autoIncrementId(): int
|
private function autoIncrementId(): int
|
||||||
|
|
@ -42,7 +50,8 @@ class FakeCarrierRepository implements CarrierRepository
|
||||||
return array_map(function (Carrier $carrier) {
|
return array_map(function (Carrier $carrier) {
|
||||||
return new Carrier(
|
return new Carrier(
|
||||||
$carrier->getId(),
|
$carrier->getId(),
|
||||||
$carrier->getEmail()
|
$carrier->getEmail(),
|
||||||
|
$carrier->getCompanyName(),
|
||||||
);
|
);
|
||||||
}, $this->existingCarriers);
|
}, $this->existingCarriers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ class CreateCarrierTest extends TestCase
|
||||||
public function test_carrier_is_created(): void
|
public function test_carrier_is_created(): void
|
||||||
{
|
{
|
||||||
$email = 'joe@shmoe.com';
|
$email = 'joe@shmoe.com';
|
||||||
|
$company = 'test company';
|
||||||
$carrierRepo = new FakeCarrierRepository();
|
$carrierRepo = new FakeCarrierRepository();
|
||||||
$dto = new CreateCarrierRequest($email);
|
$dto = new CreateCarrierRequest($email, $company);
|
||||||
$useCase = new CreateCarrier($dto, $carrierRepo);
|
$useCase = new CreateCarrier($dto, $carrierRepo);
|
||||||
$response = $useCase->execute();
|
$response = $useCase->execute();
|
||||||
$foundCarrier = $carrierRepo->find($response->getId());
|
$foundCarrier = $carrierRepo->find($response->getId());
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,13 @@ class GetAllCarriersTest extends TestCase
|
||||||
public function test_get_one_carrier(): void
|
public function test_get_one_carrier(): void
|
||||||
{
|
{
|
||||||
$repo = new FakeCarrierRepository();
|
$repo = new FakeCarrierRepository();
|
||||||
$repo->save(new Carrier(0, 'email@email.com'));
|
$repo->save(new Carrier(0, 'email@email.com', 'test Company'));
|
||||||
$useCase = new GetAllCarriers($repo);
|
$useCase = new GetAllCarriers($repo);
|
||||||
$response = $useCase->execute();
|
$response = $useCase->execute();
|
||||||
$this->assertEquals([new Carrier(0, 'email@email.com')], $response);
|
$this->assertEquals(
|
||||||
|
[new Carrier(0, 'email@email.com', 'test Company')],
|
||||||
|
$response
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_zero_carriers(): void
|
public function test_get_zero_carriers(): void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue