feat: booking details pdf
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Email\Mailer;
|
||||
use App\Email\PdfAttachment;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
@@ -17,6 +18,7 @@ use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingPdfGenerator;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\CmsDataProvider;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
@@ -522,6 +524,57 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service->sendBookingConfirmedCustomerEmail($booking);
|
||||
}
|
||||
|
||||
public function testTheConfirmationEmailCarriesTheBookingPdf(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setStatus(AccommodationBookingStatus::Confirmed);
|
||||
|
||||
$attachment = new PdfAttachment('%PDF-1.7', 'buchung.pdf');
|
||||
|
||||
$pdfGenerator = $this->createMock(AccommodationBookingPdfGenerator::class);
|
||||
$pdfGenerator->expects(self::once())->method('createAttachment')->with($booking)->willReturn($attachment);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::anything(),
|
||||
self::callback(fn (array $options) => [$attachment] === $options['attachments']),
|
||||
);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, pdfGenerator: $pdfGenerator);
|
||||
|
||||
$service->sendBookingConfirmedCustomerEmail($booking);
|
||||
}
|
||||
|
||||
public function testAFailingPdfStillLetsTheConfirmationEmailGoOut(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setStatus(AccommodationBookingStatus::Confirmed);
|
||||
|
||||
$pdfGenerator = $this->createMock(AccommodationBookingPdfGenerator::class);
|
||||
$pdfGenerator->method('createAttachment')->willThrowException(new \RuntimeException('no prices'));
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::anything(),
|
||||
self::callback(fn (array $options) => [] === $options['attachments']),
|
||||
);
|
||||
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$logger->expects(self::once())->method('warning');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, logger: $logger, pdfGenerator: $pdfGenerator);
|
||||
|
||||
$service->sendBookingConfirmedCustomerEmail($booking);
|
||||
}
|
||||
|
||||
/**
|
||||
* The discount arithmetic itself lives in — and is tested with —
|
||||
* AccommodationBookingBreakdownCalculator; what matters here is that the raw breakdown is
|
||||
@@ -563,6 +616,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
?LoggerInterface $logger = null,
|
||||
?AccommodationBookingLinkSigner $linkSigner = null,
|
||||
?AccommodationBookingBreakdownCalculator $breakdownCalculator = null,
|
||||
?AccommodationBookingPdfGenerator $pdfGenerator = null,
|
||||
): AccommodationBookingService {
|
||||
$accommodation = (new Accommodation())
|
||||
->setName('Hotel')
|
||||
@@ -592,6 +646,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$this->createMock(CmsDataProvider::class),
|
||||
$linkSigner ?? $this->createMock(AccommodationBookingLinkSigner::class),
|
||||
$breakdownCalculator ?? $this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$pdfGenerator ?? $this->createMock(AccommodationBookingPdfGenerator::class),
|
||||
'[email protected]',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user