test update bid use case
This commit is contained in:
parent
e4c535201b
commit
9e2e6d9449
4 changed files with 89 additions and 0 deletions
|
|
@ -59,18 +59,38 @@ class Bid
|
||||||
return $this->cost;
|
return $this->cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCost(int $cost): void
|
||||||
|
{
|
||||||
|
$this->cost = $cost;
|
||||||
|
}
|
||||||
|
|
||||||
public function getNotes(): ?string
|
public function getNotes(): ?string
|
||||||
{
|
{
|
||||||
return $this->notes;
|
return $this->notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setNotes(string $notes): void
|
||||||
|
{
|
||||||
|
$this->notes = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFileAttachments(): ?array
|
public function getFileAttachments(): ?array
|
||||||
{
|
{
|
||||||
return $this->fileAttachments;
|
return $this->fileAttachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setFileAttachments(array $attachments): void
|
||||||
|
{
|
||||||
|
$this->fileAttachments = $attachments;
|
||||||
|
}
|
||||||
|
|
||||||
public function isClosed(): bool
|
public function isClosed(): bool
|
||||||
{
|
{
|
||||||
return $this->isClosed;
|
return $this->isClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setIsClosed(bool $isClosed): void
|
||||||
|
{
|
||||||
|
$this->isClosed = $isClosed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
src/Bid/UseCases/UpdateBid.php
Normal file
22
src/Bid/UseCases/UpdateBid.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Bid/UseCases/UpdateBidRequest.php
Normal file
11
src/Bid/UseCases/UpdateBidRequest.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreightQuote\Bid\UseCases;
|
||||||
|
|
||||||
|
class UpdateBidRequest
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $bidId,
|
||||||
|
public array $data,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
36
tests/Unit/Bid/UseCases/UpdateBidTest.php
Normal file
36
tests/Unit/Bid/UseCases/UpdateBidTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue