62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Aggregate\AcceptOrderCommand;
|
|
use App\Contract\OrderDto;
|
|
use App\Contract\ProductDto;
|
|
use App\Entity\Client;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Serializer\SerializerInterface;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
class OrderServiceTest extends TestCase
|
|
{
|
|
private const ORDER_ID = '018eddae-ff52-7813-9f88-ada9e61a76f3';
|
|
private const CLIENT_ID = '018edd2e-894a-78d7-b10c-16e05ca933a3';
|
|
|
|
private function createValidOrderDto(): OrderDto
|
|
{
|
|
return new OrderDto(
|
|
orderId: Uuid::fromRfc4122(self::ORDER_ID),
|
|
clientId: Uuid::fromRfc4122(self::CLIENT_ID),
|
|
products: [
|
|
new ProductDto('p1', 1, 100, 100),
|
|
new ProductDto('p2', 2, 300, 100),
|
|
new ProductDto('p3', 3, 200, 100),
|
|
new ProductDto('p4', 4, 400, 700),
|
|
new ProductDto('p5', 5, 800, 700),
|
|
]
|
|
);
|
|
}
|
|
|
|
public function testCrmGetsCalledOnValidOrderRequest()
|
|
{
|
|
$httpClientMock = $this->getMockBuilder(HttpClientInterface::class)->getMock();
|
|
$serializerMock = $this->getMockBuilder(SerializerInterface::class)->getMock();
|
|
|
|
$sut = new OrderService($httpClientMock, $serializerMock);
|
|
|
|
$httpClientMock->expects($this->once())->method('request')->with('POST', '/order');
|
|
|
|
$order = new AcceptOrderCommand(
|
|
$this->createValidOrderDto(),
|
|
$this->createClient(balance: 10000)
|
|
);
|
|
|
|
$sut->acceptOrder($order);
|
|
}
|
|
|
|
private function createClient(int $balance): Client
|
|
{
|
|
return new Client(
|
|
clientId: Uuid::fromRfc4122(self::CLIENT_ID),
|
|
name: 'Stub',
|
|
initialBalance: $balance,
|
|
currentBalance: $balance
|
|
);
|
|
}
|
|
|
|
}
|