fix: treat dates without price as unavailable
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Service\AccommodationPriceCoverage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AccommodationPriceCoverageTest extends TestCase
|
||||
{
|
||||
public function testCoversOnlyDaysWithinPricePeriod(): void
|
||||
{
|
||||
$coverage = new AccommodationPriceCoverage($this->createMock(AccommodationPriceRepository::class));
|
||||
|
||||
$covered = $coverage->coveredDatesFor(
|
||||
[$this->price('2026-06-01', '2026-06-09')],
|
||||
new \DateTimeImmutable('2026-06-01'),
|
||||
new \DateTimeImmutable('2026-06-12'),
|
||||
);
|
||||
|
||||
// dateTo is the last night, so 2026-06-09 is still covered
|
||||
self::assertSame([
|
||||
'2026-06-01', '2026-06-02', '2026-06-03', '2026-06-04', '2026-06-05',
|
||||
'2026-06-06', '2026-06-07', '2026-06-08', '2026-06-09',
|
||||
], array_keys($covered));
|
||||
}
|
||||
|
||||
public function testGapBetweenPricePeriodsStaysUncovered(): void
|
||||
{
|
||||
$coverage = new AccommodationPriceCoverage($this->createMock(AccommodationPriceRepository::class));
|
||||
|
||||
$covered = $coverage->coveredDatesFor(
|
||||
[$this->price('2026-06-01', '2026-06-02'), $this->price('2026-06-05', '2026-06-06')],
|
||||
new \DateTimeImmutable('2026-06-01'),
|
||||
new \DateTimeImmutable('2026-06-06'),
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
['2026-06-01', '2026-06-02', '2026-06-05', '2026-06-06'],
|
||||
array_keys($covered),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoPricesMeansNoCoverage(): void
|
||||
{
|
||||
$coverage = new AccommodationPriceCoverage($this->createMock(AccommodationPriceRepository::class));
|
||||
|
||||
$covered = $coverage->coveredDatesFor(
|
||||
[],
|
||||
new \DateTimeImmutable('2026-06-01'),
|
||||
new \DateTimeImmutable('2026-06-03'),
|
||||
);
|
||||
|
||||
self::assertSame([], $covered);
|
||||
}
|
||||
|
||||
private function price(string $from, string $to): AccommodationPrice
|
||||
{
|
||||
$price = new AccommodationPrice();
|
||||
$price->setDateFrom(new \DateTimeImmutable($from));
|
||||
$price->setDateTo(new \DateTimeImmutable($to));
|
||||
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user