test update bid use case

This commit is contained in:
Yisroel Baum 2025-11-25 20:05:29 +02:00
parent e4c535201b
commit 9e2e6d9449
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 89 additions and 0 deletions

View file

@ -59,18 +59,38 @@ class Bid
return $this->cost;
}
public function setCost(int $cost): void
{
$this->cost = $cost;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(string $notes): void
{
$this->notes = $notes;
}
public function getFileAttachments(): ?array
{
return $this->fileAttachments;
}
public function setFileAttachments(array $attachments): void
{
$this->fileAttachments = $attachments;
}
public function isClosed(): bool
{
return $this->isClosed;
}
public function setIsClosed(bool $isClosed): void
{
$this->isClosed = $isClosed;
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace FreightQuote\Bid\UseCases;
use FreightQuote\Bid\BidRepository;
class UpdateBid
{
public function __construct(
private BidRepository $bidRepo,
) {}
public function execute(UpdateBidRequest $dto): void
{
$bid = $this->bidRepo->find($dto->bidId);
$bid->setCost($dto->data['cost']);
$bid->setIsClosed($dto->data['isClosed']);
$bid->setNotes($dto->data['notes']);
$bid->setFileAttachments($dto->data['fileAttachments']);
$this->bidRepo->save($bid);
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace FreightQuote\Bid\UseCases;
class UpdateBidRequest
{
public function __construct(
public int $bidId,
public array $data,
) {}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Bid\UseCases;
use FreightQuote\Bid\Bid;
use FreightQuote\Bid\UseCases\UpdateBid;
use FreightQuote\Bid\UseCases\UpdateBidRequest;
use PHPUnit\Framework\TestCase;
use Tests\Fakes\Bid\FakeBidRepository;
class UpdateBidTest extends TestCase
{
public function test_update(): void
{
$bidRepo = new FakeBidRepository();
$bidRepo->save(new Bid(
0, 0, 0, false, false, null, null, null
));
$useCase = new UpdateBid($bidRepo);
$dto = new UpdateBidRequest(
bidId: 0,
data: [
'isClosed' => true,
'cost' => 1,
'notes' => 'some notes',
'fileAttachments' => ['/path/to/file']
],
);
$useCase->execute($dto);
$bid = $bidRepo->find(0);
$this->assertEquals(true, $bid->isClosed());
$this->assertEquals(1, $bid->getCost());
$this->assertEquals('some notes', $bid->getNotes());
$this->assertEquals(['/path/to/file'], $bid->getFileAttachments());
}
}