91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Controller\Api;
|
|
|
|
use App\BpnConnect\ContingentsClient;
|
|
use App\Controller\Api\ContingentController;
|
|
use App\Entity\Groups\AccommodationPrice;
|
|
use App\Repository\Groups\AccommodationPriceRepository;
|
|
use App\Repository\Groups\AccommodationRepository;
|
|
use App\Service\AccommodationPriceCoverage;
|
|
use App\Service\PriceTimelineBuilder;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Contracts\Cache\CacheInterface;
|
|
|
|
class ContingentControllerTest extends TestCase
|
|
{
|
|
public function testEnrichEntryIncludesPricingMetadata(): void
|
|
{
|
|
$controller = $this->createController();
|
|
$price = $this->createPrice();
|
|
|
|
$result = $this->enrichEntry($controller, '2026-07-06', 'available', [$price], ['2026-07-06' => true]);
|
|
|
|
self::assertSame('available', $result['status']);
|
|
self::assertSame(4, $result['includedPax']);
|
|
self::assertSame(3, $result['minNights']);
|
|
self::assertSame(123.45, $result['pricePerNight']);
|
|
self::assertSame('EUR', $result['currency']);
|
|
}
|
|
|
|
public function testEnrichEntryBlocksDayWithoutPrice(): void
|
|
{
|
|
$controller = $this->createController();
|
|
$price = $this->createPrice();
|
|
|
|
$result = $this->enrichEntry($controller, '2026-08-01', 'OK', [$price], ['2026-07-06' => true]);
|
|
|
|
self::assertSame('BLOCKED', $result['status']);
|
|
self::assertNull($result['pricePerNight']);
|
|
self::assertNull($result['includedPax']);
|
|
self::assertNull($result['minNights']);
|
|
}
|
|
|
|
private function createController(): ContingentController
|
|
{
|
|
return new ContingentController(
|
|
$this->createMock(ContingentsClient::class),
|
|
$this->createMock(AccommodationRepository::class),
|
|
$this->createMock(AccommodationPriceRepository::class),
|
|
$this->createMock(CacheInterface::class),
|
|
new PriceTimelineBuilder(),
|
|
new AccommodationPriceCoverage($this->createMock(AccommodationPriceRepository::class)),
|
|
$this->createMock(LoggerInterface::class),
|
|
);
|
|
}
|
|
|
|
private function createPrice(): AccommodationPrice
|
|
{
|
|
$price = new AccommodationPrice();
|
|
$price->setDateFrom(new \DateTimeImmutable('2026-07-01'));
|
|
$price->setDateTo(new \DateTimeImmutable('2026-07-31'));
|
|
$price->setIncludedPax(4);
|
|
$price->setPricePerNight(12345);
|
|
$price->setPriceAdditionalPerson(1500);
|
|
$price->setMinNights(3);
|
|
|
|
return $price;
|
|
}
|
|
|
|
/**
|
|
* @param AccommodationPrice[] $prices
|
|
* @param array<string, true> $covered
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function enrichEntry(
|
|
ContingentController $controller,
|
|
string $date,
|
|
string $status,
|
|
array $prices,
|
|
array $covered,
|
|
): array {
|
|
$method = new \ReflectionMethod($controller, 'enrichEntry');
|
|
|
|
return $method->invoke($controller, $date, $status, $prices, $covered, 'EUR');
|
|
}
|
|
}
|