create bid files
This commit is contained in:
parent
f322a0f80e
commit
d6b3b4b59e
3 changed files with 94 additions and 0 deletions
32
src/Bid/Bid.php
Normal file
32
src/Bid/Bid.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/Bid/BidRepository.php
Normal file
8
src/Bid/BidRepository.php
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreightQuote\Bid;
|
||||||
|
|
||||||
|
interface BidRepository
|
||||||
|
{
|
||||||
|
public function save(Bid $bid): Bid;
|
||||||
|
}
|
||||||
54
tests/Fakes/Bid/FakeBidRepository.php
Normal file
54
tests/Fakes/Bid/FakeBidRepository.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue