test get bid and throws error on invalid id
This commit is contained in:
parent
b17f6005b7
commit
bc6e3e47fe
4 changed files with 59 additions and 0 deletions
|
|
@ -5,4 +5,5 @@ namespace FreightQuote\Bid;
|
||||||
interface BidRepository
|
interface BidRepository
|
||||||
{
|
{
|
||||||
public function save(Bid $bid): Bid;
|
public function save(Bid $bid): Bid;
|
||||||
|
public function find(string $id): ?Bid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
src/Bid/UseCases/GetBidForCarrier.php
Normal file
26
src/Bid/UseCases/GetBidForCarrier.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreightQuote\Bid\UseCases;
|
||||||
|
|
||||||
|
use FreightQuote\Bid\Bid;
|
||||||
|
use FreightQuote\Bid\BidRepository;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class GetBidForCarrier
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private BidRepository $bidRepo,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function execute(GetBidForCarrierRequest $dto): Bid
|
||||||
|
{
|
||||||
|
$bid = $this->bidRepo->find($dto->id);
|
||||||
|
if ($bid === null) {
|
||||||
|
throw new InvalidArgumentException('Bid not found!');
|
||||||
|
}
|
||||||
|
return $bid;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/Bid/UseCases/GetBidForCarrierRequest.php
Normal file
10
src/Bid/UseCases/GetBidForCarrierRequest.php
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreightQuote\Bid\UseCases;
|
||||||
|
|
||||||
|
class GetBidForCarrierRequest
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $id,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
22
tests/Unit/Bid/UseCases/GetBidForCarrierTest.php
Normal file
22
tests/Unit/Bid/UseCases/GetBidForCarrierTest.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Bid\UseCases;
|
||||||
|
|
||||||
|
use FreightQuote\Bid\UseCases\GetBidForCarrier;
|
||||||
|
use FreightQuote\Bid\UseCases\GetBidForCarrierRequest;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Tests\Fakes\Bid\FakeBidRepository;
|
||||||
|
|
||||||
|
class GetBidForCarrierTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_nonexistant_bid_throws_error(): void
|
||||||
|
{
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$bidId = '12345abcd';
|
||||||
|
$dto = new GetBidForCarrierRequest($bidId);
|
||||||
|
$bidRepo = new FakeBidRepository();
|
||||||
|
$useCase = new GetBidForCarrier($bidRepo);
|
||||||
|
$foundBid = $useCase->execute($dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue