create bid files

This commit is contained in:
Yisroel Baum 2025-11-17 22:33:11 +02:00
parent f322a0f80e
commit d6b3b4b59e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 94 additions and 0 deletions

32
src/Bid/Bid.php Normal file
View file

@ -0,0 +1,32 @@
<?php
namespace FreightQuote\Bid;
class Bid
{
public function __construct(
private ?string $id,
private int $freightOrderId,
private int $carrierId,
) {}
public function getId(): ?string
{
return $this->id;
}
public function setId(string $id): void
{
$this->id = $id;
}
public function getFreightOrderId(): int
{
return $this->freightOrderId;
}
public function getCarrierId(): int
{
return $this->carrierId;
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace FreightQuote\Bid;
interface BidRepository
{
public function save(Bid $bid): Bid;
}

View file

@ -0,0 +1,54 @@
<?php
namespace Tests\Fakes\Bid;
use FreightQuote\Bid\Bid;
use FreightQuote\Bid\BidRepository;
class FakeBidRepository implements BidRepository
{
/**
* @var Bid[]
*/
private array $existingBids = [];
public function save(Bid $bid): Bid
{
$id = $bid->getId();
if ($id === null) {
$id = $this->getUniqueId();
$bid->setId($id);
}
$this->existingBids[$id] = $bid;
return new Bid(
$id,
$bid->getFreightOrderId(),
$bid->getCarrierId(),
);
}
public function find(string $id): ?Bid
{
foreach ($this->existingBids as $bid) {
if ($bid->getId() === $id) {
return new Bid(
$id,
$bid->getFreightOrderId(),
$bid->getCarrierId(),
);
}
}
return null;
}
private function getUniqueId(): string
{
$id = uniqid('', true);
while ($this->find($id) !== null) {
$id = uniqid('', true);
}
return $id;
}
}