Compare commits

...
3 Commits
31 changed files with 612 additions and 329 deletions

No files matched your search

+7
View File
@@ -61,6 +61,13 @@ ACCOMMODATION_TERMS_IT=
BPN_CONNECT_BASE_URL=https://bpn-connect.ep-reisen.app
BPN_CONNECT_API_KEY=
# ClickUp task created when an accommodation booking is confirmed. Token/ids are secrets and
# stay empty here — set them in .env.local. Without them the handler skips with a warning.
CLICKUP_API_TOKEN=
CLICKUP_LIST_ID=
CLICKUP_TEMPLATE_ID=
CLICKUP_API_BASE_URL=https://api.clickup.com/api/v2
APP_BPN_USER=
APP_BPN_PASSWORD=
APP_BPN_IP=
+1
View File
@@ -25,6 +25,7 @@ framework:
Symfony\Component\Notifier\Message\ChatMessage: async
Symfony\Component\Notifier\Message\SmsMessage: async
App\Message\MailjetNewsletterEventMessage: async
App\Message\CreateClickUpBookingTaskMessage: async
# Route your messages to the transports
# 'App\Message\YourMessage': async
+8 -1
View File
@@ -329,7 +329,14 @@ services:
App\BpnConnect\ContingentsClient:
parent: App\BpnConnect\AbstractApiClient
App\Service\MailjetApiClient:
App\ClickUp\ApiClient:
arguments:
$apiToken: '%env(default::CLICKUP_API_TOKEN)%'
$listId: '%env(default::CLICKUP_LIST_ID)%'
$templateId: '%env(default::CLICKUP_TEMPLATE_ID)%'
$baseUrl: '%env(default::CLICKUP_API_BASE_URL)%'
App\Mailjet\ApiClient:
arguments:
$apiKey: '%env(default::MAILJET_API_KEY)%'
$apiSecret: '%env(default::MAILJET_API_SECRET)%'
+104
View File
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace App\ClickUp;
use App\ClickUp\Exception\ClickUpException;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class ApiClient
{
private const string DEFAULT_BASE_URL = 'https://api.clickup.com/api/v2';
// Creating a task from a template regularly takes several seconds on ClickUp's side, so these
// ceilings sit well above the ones the BpnConnect client uses. They exist to stop a hung
// upstream from pinning a worker forever, not to enforce a latency budget.
private const int IDLE_TIMEOUT_SECONDS = 30;
private const int MAX_DURATION_SECONDS = 120;
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly LoggerInterface $logger,
private readonly ?string $apiToken = null,
private readonly ?string $listId = null,
private readonly ?string $templateId = null,
private readonly ?string $baseUrl = null,
) {
}
/**
* Environments without ClickUp credentials (dev, test, staging) must not fail — callers check
* this instead of letting assertConfigured() blow up.
*/
public function isConfigured(): bool
{
return null !== $this->apiToken && '' !== $this->apiToken
&& null !== $this->listId && '' !== $this->listId
&& null !== $this->templateId && '' !== $this->templateId;
}
/**
* Creates a task from the configured template and returns the new task id.
*/
public function createTaskFromTemplate(string $name): string
{
$data = $this->request('POST', sprintf('/list/%s/taskTemplate/%s', $this->listId, $this->templateId), [
'name' => $name,
]);
$id = $data['id'] ?? null;
if (!is_string($id) || '' === $id) {
throw new ClickUpException('ClickUp did not return a task id for the created task.');
}
return $id;
}
public function updateTaskStatus(string $taskId, string $status): void
{
$this->request('PUT', '/task/'.$taskId, ['status' => $status]);
}
/**
* @param array<string, mixed> $payload
*
* @return array<string, mixed>
*/
private function request(string $method, string $path, array $payload): array
{
$this->assertConfigured();
try {
$response = $this->httpClient->request($method, ($this->baseUrl ?? self::DEFAULT_BASE_URL).$path, [
'headers' => [
// ClickUp deviates from the usual scheme: the raw token goes into the
// Authorization header, without a "Bearer " prefix.
'Authorization' => $this->apiToken,
],
'json' => $payload,
'timeout' => self::IDLE_TIMEOUT_SECONDS,
'max_duration' => self::MAX_DURATION_SECONDS,
]);
return $response->toArray();
} catch (ExceptionInterface $e) {
$this->logger->error('ClickUp request failed', [
'method' => $method,
'path' => $path,
'error' => $e->getMessage(),
]);
throw new ClickUpException('ClickUp request failed: '.$e->getMessage(), 0, $e);
}
}
private function assertConfigured(): void
{
if (!$this->isConfigured()) {
throw new ClickUpException('ClickUp client is not configured (missing CLICKUP_API_TOKEN, CLICKUP_LIST_ID or CLICKUP_TEMPLATE_ID).');
}
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\ClickUp\Exception;
class ClickUpException extends \RuntimeException
{
}
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace App\Command;
use App\Exception\NewsletterProviderException;
use App\Service\MailjetApiClient;
use App\Mailjet\ApiClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
@@ -31,7 +31,7 @@ final class MailjetNewsletterWebhookCommand extends Command
private const int WEBHOOK_VERSION = 2;
public function __construct(
private readonly MailjetApiClient $mailjetApiClient,
private readonly ApiClient $mailjetApiClient,
#[Autowire(env: 'APP_BASE_URL')]
private readonly string $defaultBaseUrl,
#[Autowire(env: 'MAILJET_WEBHOOK_BASIC_PASSWORD')]
@@ -6,11 +6,13 @@ namespace App\Controller\Admin\AccommodationBooking;
use App\Entity\Groups\AccommodationBooking;
use App\Htmx\HxRedirectResponse;
use App\Message\CreateClickUpBookingTaskMessage;
use App\Service\AccommodationBookingService;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
@@ -19,6 +21,7 @@ class ConfirmController extends AbstractController
{
public function __construct(
private readonly AccommodationBookingService $bookingService,
private readonly MessageBusInterface $messageBus,
private readonly LoggerInterface $logger,
) {
}
@@ -53,6 +56,9 @@ class ConfirmController extends AbstractController
'id' => $booking->getId(),
]);
// Creating the ClickUp task takes seconds, so it must not hang off this request.
$this->messageBus->dispatch(new CreateClickUpBookingTaskMessage((int) $booking->getId()));
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_show', ['id' => $booking->getId()]));
}
@@ -1,55 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin\AccommodationBooking;
use App\Entity\Groups\AccommodationBooking;
use App\Htmx\HxRedirectResponse;
use App\Service\AccommodationBookingService;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[IsGranted('ROLE_GROUPS_MANAGER')]
class GenerateAccessLinkController extends AbstractController
{
public function __construct(
private readonly AccommodationBookingService $bookingService,
private readonly LoggerInterface $logger,
) {
}
#[Route('/admin/accommodation-booking/{id}/generate-access-link', name: 'app_admin_accommodationbooking_generate_access_link')]
public function index(AccommodationBooking $booking, Request $request): Response
{
// A draft has not been offered to anyone yet, so there is nothing a link could show.
if (!$booking->isCustomerAccessible()) {
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
}
if ($request->isMethod(Request::METHOD_POST)) {
if (!$this->isCsrfTokenValid('generate_accommodation_booking_access_link_'.$booking->getId(), $request->request->getString('_token'))) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
}
$this->bookingService->regenerateAccessLink($booking);
$this->addFlash('success', 'Der Zugangslink wurde neu generiert.');
$this->logger->info('Generated accommodation booking access link', [
'id' => $booking->getId(),
]);
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_show', ['id' => $booking->getId()]));
}
return $this->render('admin/accommodation_booking/modal_generate_access_link.html.twig', [
'booking' => $booking,
'csrf_token_id' => 'generate_accommodation_booking_access_link_'.$booking->getId(),
]);
}
}
@@ -43,9 +43,9 @@ class SendAccessLinkController extends AbstractController
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_edit', ['id' => $booking->getId()]));
}
$this->bookingService->sendCustomerConfirmationEmail($booking);
$this->bookingService->sendAccessLink($booking);
$this->addFlash('success', 'Der Zugangslink wurde dem Kunden per E-Mail zugestellt.');
$this->addFlash('success', 'Ein neuer Zugangslink wurde dem Kunden per E-Mail zugestellt.');
$this->logger->info('Sent accommodation booking access link', [
'id' => $booking->getId(),
@@ -2,13 +2,13 @@
declare(strict_types=1);
namespace App\Service;
namespace App\Mailjet;
use App\Exception\NewsletterProviderException;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class MailjetApiClient
class ApiClient
{
private const string DEFAULT_BASE_URL = 'https://api.mailjet.com/v3/REST';
private const int NAME_MAX_LENGTH = 255;
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace App\Message;
final class CreateClickUpBookingTaskMessage
{
public function __construct(
public readonly int $bookingId,
) {
}
}
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace App\MessageHandler;
use App\ClickUp\ApiClient;
use App\ClickUp\Exception\ClickUpException;
use App\Message\CreateClickUpBookingTaskMessage;
use App\Repository\Groups\AccommodationBookingRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
final class CreateClickUpBookingTaskHandler
{
/** The status every freshly created group-operations task starts in. */
public const string TASK_STATUS = 'GRO';
public function __construct(
private readonly AccommodationBookingRepository $bookingRepository,
private readonly ApiClient $clickUpClient,
private readonly LoggerInterface $logger,
) {
}
public function __invoke(CreateClickUpBookingTaskMessage $message): void
{
if (!$this->clickUpClient->isConfigured()) {
$this->logger->warning('ClickUp is not configured, skipping task creation', [
'bookingId' => $message->bookingId,
]);
return;
}
$booking = $this->bookingRepository->find($message->bookingId);
if (null === $booking) {
// The booking is gone — a retry cannot bring it back.
$this->logger->warning('Accommodation booking not found, skipping ClickUp task creation', [
'bookingId' => $message->bookingId,
]);
return;
}
$hotelCode = $booking->getAccommodation()?->getCalendarCode();
$dateFrom = $booking->getDateFrom();
$contactName = trim(trim((string) $booking->getFirstName()).' '.trim((string) $booking->getLastName()));
if (null === $hotelCode || '' === $hotelCode || null === $dateFrom || '' === $contactName) {
// A task named " 2026-08-20 " helps nobody, and no amount of retrying fills the gaps.
$this->logger->warning('Accommodation booking lacks the data for a ClickUp task name, skipping', [
'bookingId' => $message->bookingId,
]);
return;
}
$name = sprintf('%s %s %s', $hotelCode, $dateFrom->format('Y-m-d'), $contactName);
$taskId = $this->clickUpClient->createTaskFromTemplate($name);
try {
$this->clickUpClient->updateTaskStatus($taskId, self::TASK_STATUS);
} catch (ClickUpException $e) {
// Deliberately swallowed: letting this bubble would retry the whole handler and create
// a second task in ClickUp. A task with the wrong status can be fixed by hand, a
// duplicate task cannot be un-created.
$this->logger->error('ClickUp task created but status update failed', [
'bookingId' => $message->bookingId,
'taskId' => $taskId,
'status' => self::TASK_STATUS,
'error' => $e->getMessage(),
]);
return;
}
$this->logger->info('Created ClickUp task for accommodation booking', [
'bookingId' => $message->bookingId,
'taskId' => $taskId,
]);
}
}
+2 -2
View File
@@ -13,8 +13,8 @@ namespace App\Model;
final readonly class CmsHotelData
{
/**
* @param array<string, mixed>|null $images
* @param array<string, array{label?: string|null, value?: mixed}>|null $icons
* @param array<string, mixed>|null $images
* @param list<array{icon: string, label: string|false}>|null $icons
*/
public function __construct(
public ?string $name,
+8 -4
View File
@@ -492,13 +492,15 @@ class AccommodationBookingService
}
/**
* Explicit admin action: (re)issues the access link, invalidating any previously issued
* link for this booking. No email side effect — sending is a separate, explicit admin
* action via sendCustomerConfirmationEmail().
* Explicit admin action: mails the access link again, refreshing its validity first so the
* customer always receives a link that is good for another full TTL — the mail is the only
* way a link reaches the customer, so sending and issuing belong together.
* The previously issued link stops working, which is the point: one booking has one valid
* link at a time.
* A no-op for a record that is not customer accessible yet, for the same reason as
* issueAccessLink().
*/
public function regenerateAccessLink(AccommodationBooking $booking): void
public function sendAccessLink(AccommodationBooking $booking): void
{
if (!$booking->isCustomerAccessible()) {
return;
@@ -506,6 +508,8 @@ class AccommodationBookingService
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable());
$this->entityManager->flush();
$this->sendCustomerConfirmationEmail($booking);
}
/**
+1 -1
View File
@@ -64,7 +64,7 @@ class CmsDataProvider
* room_types?: string,
* additional_information?: string,
* images?: array<string, mixed>,
* icons?: array<string, bool|string>,
* icons?: list<array{icon: string, label: string|false}>,
* region?: array{
* name: string,
* latitude: float,
+2 -1
View File
@@ -9,6 +9,7 @@ use App\Entity\NewsletterConsent;
use App\Entity\NewsletterOptInRequest;
use App\Exception\NewsletterListNotAllowedException;
use App\Exception\NewsletterProviderException;
use App\Mailjet\ApiClient;
use App\Model\NewsletterConfirmationResult;
use App\Model\NewsletterSubscriptionRequestResult;
use App\Repository\NewsletterConsentRepository;
@@ -27,7 +28,7 @@ class NewsletterManager
private readonly NewsletterOptInRequestRepository $optInRequestRepository,
private readonly NewsletterConsentRepository $consentRepository,
private readonly EntityManagerInterface $entityManager,
private readonly MailjetApiClient $newsletterService,
private readonly ApiClient $newsletterService,
private readonly Mailer $mailer,
private readonly LoggerInterface $logger,
private readonly int $newsletterConfirmationTtlHours,
@@ -1,8 +0,0 @@
{% extends 'htmx_confirmation_modal.html.twig' %}
{% block content %}
<div>
Möchtest du für <em>{{ booking.groupName }}</em> einen neuen Zugangslink generieren?
Ein zuvor generierter Link wird dadurch ungültig.
</div>
{% endblock %}
@@ -2,7 +2,7 @@
{% block content %}
<div>
Möchtest du den aktuellen Zugangslink für <em>{{ booking.groupName }}</em> an
<em>{{ booking.email }}</em> senden?
Möchtest du einen neuen Zugangslink für <em>{{ booking.groupName }}</em> an
<em>{{ booking.email }}</em> senden? Der zuvor gesendete Link wird dadurch ungültig.
</div>
{% endblock %}
@@ -214,10 +214,10 @@
<h2 class="text-lg font-bold mb-2">Zugangslink</h2>
{% if not booking.customerAccessible %}
<p class="text-sm text-gray-500">
Ein Zugangslink wird beim Versand des Angebots erzeugt und kann erst danach erneuert werden.
Ein Zugangslink wird beim Versand des Angebots erzeugt.
</p>
{% else %}
{% if accessLink %}
{% elseif accessLink %}
<div class="flex items-center gap-2">
<button type="button"
class="button button--secondary button--small"
data-controller="clipboard"
@@ -226,33 +226,24 @@
data-action="clipboard#copy">
{{ icon('copy', 'w-4 h-4') }} Link kopieren
</button>
<p class="text-xs text-gray-500 mt-1">
Gültig bis {{ accessLinkExpiresAt | date('d.m.Y') }}
{% if accessLinkExpiresAt < date() %}
<span class="text-red-600 font-medium">(abgelaufen)</span>
{% endif %}
</p>
{% else %}
<p class="text-sm text-gray-500">Es wurde noch kein Zugangslink generiert.</p>
{% endif %}
<div class="mt-2 flex items-center gap-2">
<button type="button"
class="button button--secondary button--small"
hx-get="{{ path('app_admin_accommodationbooking_generate_access_link', { id: booking.id }) }}"
hx-get="{{ path('app_admin_accommodationbooking_send_access_link', { id: booking.id }) }}"
hx-target="body"
hx-swap="beforeend">
{{ accessLink ? 'Link erneut generieren' : 'Link generieren' }}
Link senden
</button>
{% if accessLink %}
<button type="button"
class="button button--secondary button--small"
hx-get="{{ path('app_admin_accommodationbooking_send_access_link', { id: booking.id }) }}"
hx-target="body"
hx-swap="beforeend">
Link senden
</button>
{% endif %}
</div>
<p class="text-xs text-gray-500 mt-1">
Gültig bis {{ accessLinkExpiresAt | date('d.m.Y') }}
{% if accessLinkExpiresAt < date() %}
<span class="text-red-600 font-medium">(abgelaufen)</span>
{% endif %}
</p>
{% else %}
<p class="text-sm text-gray-500">
Der Zugangslink wird beim Versand des Angebots erzeugt.
</p>
{% endif %}
</div>
+6 -24
View File
@@ -109,36 +109,18 @@
} %}
{% block body %}
{% set icons = ctx.hotelCmsData.icons %}
{% set iconMap = {
bedsCount: { icon: 'bed', label: 'Anzahl Betten' },
parkingCount: { icon: 'parking', label: 'Anzahl Parkplätze' },
altitude: { icon: 'mountain', label: 'Höhe' },
partyroom: { icon: 'party', label: 'Partyraum' },
gamesroom: { icon: 'dice', label: 'Spieleraum' },
distanceBus: { icon: 'bus', label: 'Entfernung Bus' },
distanceLift: { icon: 'lift', label: 'Entfernung Lifte' },
sauna: { icon: 'sauna', label: 'Sauna' },
shower: { icon: 'shower', label: 'Dusche' },
wifi: { icon: 'wifi', label: 'WiFi' },
} %}
{% if icons is not empty %}
<ul class="grid grid-cols-2 md:grid-cols-3 gap-2">
{% for key, value in icons %}
{% set mapping = iconMap[key] ?? null %}
{% set isBool = value is same as(true) or value is same as(false) %}
{% for item in icons %}
<li class="flex items-center gap-2">
<div class="border-2 border-gray-900 rounded-full w-16 h-16 shrink-0 flex flex-col items-center justify-center">
{% if mapping %}
{{ icon(mapping.icon, 'w-8 h-8 shrink-0 text-gray-900') }}
{% endif %}
</div>
<div class="text-sm font-bold">
{% if isBool %}
{{ mapping ? mapping.label : '' }}
{% else %}
{{ mapping ? mapping.label ~ ': ' ~ value : value }}
{% if item.icon %}
{{ icon(item.icon, 'w-8 h-8 shrink-0 text-gray-900') }}
{% endif %}
</div>
{% if item.label is not same as(false) %}
<div class="text-sm font-bold">{{ item.label }}</div>
{% endif %}
</li>
{% endfor %}
</ul>
+99
View File
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace App\Tests\ClickUp;
use App\ClickUp\ApiClient;
use App\ClickUp\Exception\ClickUpException;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class ApiClientTest extends TestCase
{
public function testCreateTaskFromTemplatePostsTheNameAndReturnsTheTaskId(): void
{
$requests = [];
$http = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['id' => 'abc123'], JSON_THROW_ON_ERROR), [
'response_headers' => ['content-type' => 'application/json'],
]);
});
$taskId = $this->client($http)->createTaskFromTemplate('WIEN01 2026-08-20 Müller');
self::assertSame('abc123', $taskId);
self::assertSame('POST', $requests[0][0]);
self::assertSame('https://clickup.test/list/555/taskTemplate/tpl-7', $requests[0][1]);
self::assertSame(['name' => 'WIEN01 2026-08-20 Müller'], json_decode((string) $requests[0][2]['body'], true, 512, JSON_THROW_ON_ERROR));
self::assertContains('Authorization: pk_secret', $requests[0][2]['headers']);
}
public function testUpdateTaskStatusPutsTheStatus(): void
{
$requests = [];
$http = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['id' => 'abc123'], JSON_THROW_ON_ERROR), [
'response_headers' => ['content-type' => 'application/json'],
]);
});
$this->client($http)->updateTaskStatus('abc123', 'GRO');
self::assertSame('PUT', $requests[0][0]);
self::assertSame('https://clickup.test/task/abc123', $requests[0][1]);
self::assertSame(['status' => 'GRO'], json_decode((string) $requests[0][2]['body'], true, 512, JSON_THROW_ON_ERROR));
}
public function testAResponseWithoutATaskIdIsAnError(): void
{
$http = new MockHttpClient(new MockResponse(json_encode(['err' => 'nope'], JSON_THROW_ON_ERROR), [
'response_headers' => ['content-type' => 'application/json'],
]));
$this->expectException(ClickUpException::class);
$this->client($http)->createTaskFromTemplate('WIEN01 2026-08-20 Müller');
}
public function testAnHttpErrorIsWrappedInADomainException(): void
{
$http = new MockHttpClient(new MockResponse('rate limited', ['http_code' => 429]));
$this->expectException(ClickUpException::class);
$this->client($http)->createTaskFromTemplate('WIEN01 2026-08-20 Müller');
}
public function testAnUnconfiguredClientReportsItselfAndRefusesToRequest(): void
{
$http = new MockHttpClient(function (): MockResponse {
self::fail('No request must be made when the client is unconfigured.');
});
$client = new ApiClient($http, new NullLogger(), 'pk_secret', '', 'tpl-7', 'https://clickup.test');
self::assertFalse($client->isConfigured());
$this->expectException(ClickUpException::class);
$client->createTaskFromTemplate('WIEN01 2026-08-20 Müller');
}
public function testAFullyConfiguredClientReportsItself(): void
{
self::assertTrue($this->client(new MockHttpClient())->isConfigured());
self::assertFalse((new ApiClient(new MockHttpClient(), new NullLogger()))->isConfigured());
}
private function client(MockHttpClient $http): ApiClient
{
return new ApiClient($http, new NullLogger(), 'pk_secret', '555', 'tpl-7', 'https://clickup.test');
}
}
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace App\Tests\Command;
use App\Command\MailjetNewsletterWebhookCommand;
use App\Service\MailjetApiClient;
use App\Mailjet\ApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
@@ -15,7 +15,7 @@ class MailjetNewsletterWebhookCommandTest extends TestCase
{
public function testRegisterCreatesWebhookAndPrintsPayload(): void
{
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailjet->expects(self::once())
->method('createEventCallbackUrl')
->with(
@@ -43,7 +43,7 @@ class MailjetNewsletterWebhookCommandTest extends TestCase
public function testRemoveDeletesWebhookById(): void
{
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailjet->expects(self::never())->method('createEventCallbackUrl');
$mailjet->expects(self::once())
->method('deleteEventCallbackUrl')
@@ -58,7 +58,7 @@ class MailjetNewsletterWebhookCommandTest extends TestCase
public function testDeactivateUsesRemoveFlow(): void
{
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailjet->expects(self::never())->method('createEventCallbackUrl');
$mailjet->expects(self::once())
->method('deleteEventCallbackUrl')
@@ -73,7 +73,7 @@ class MailjetNewsletterWebhookCommandTest extends TestCase
public function testRemoveFailsWithoutCallbackId(): void
{
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailjet->expects(self::never())->method('createEventCallbackUrl');
$mailjet->expects(self::never())->method('deleteEventCallbackUrl');
@@ -84,7 +84,7 @@ class MailjetNewsletterWebhookCommandTest extends TestCase
self::assertStringContainsString('A numeric callback ID is required', $tester->getDisplay());
}
private function createCommand(MailjetApiClient $mailjetApiClient): MailjetNewsletterWebhookCommand
private function createCommand(ApiClient $mailjetApiClient): MailjetNewsletterWebhookCommand
{
return new MailjetNewsletterWebhookCommand(
$mailjetApiClient,
@@ -7,11 +7,15 @@ namespace App\Tests\Controller\Admin\AccommodationBooking;
use App\Controller\Admin\AccommodationBooking\ConfirmController;
use App\Entity\Groups\AccommodationBooking;
use App\Enum\Groups\AccommodationBookingStatus;
use App\Message\CreateClickUpBookingTaskMessage;
use App\Service\AccommodationBookingService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
@@ -25,7 +29,7 @@ class ConfirmControllerTest extends TestCase
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('confirmBooking');
$controller = new TestableConfirmController($bookingService, $this->createMock(LoggerInterface::class));
$controller = new TestableConfirmController($bookingService, $this->neverDispatchingBus(), $this->createMock(LoggerInterface::class));
$response = $controller->index($this->receivedBooking(), Request::create('/admin/accommodation-booking/1/confirm'));
@@ -40,7 +44,14 @@ class ConfirmControllerTest extends TestCase
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::once())->method('confirmBooking')->with($booking);
$controller = new TestableConfirmController($bookingService, $this->createMock(LoggerInterface::class));
// The ClickUp task is created asynchronously because the ClickUp API is slow.
$messageBus = $this->createMock(MessageBusInterface::class);
$messageBus->expects(self::once())
->method('dispatch')
->with(self::isInstanceOf(CreateClickUpBookingTaskMessage::class))
->willReturnCallback(static fn (object $message): Envelope => new Envelope($message));
$controller = new TestableConfirmController($bookingService, $messageBus, $this->createMock(LoggerInterface::class));
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/confirm', 'POST'));
@@ -52,7 +63,7 @@ class ConfirmControllerTest extends TestCase
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('confirmBooking');
$controller = new TestableConfirmController($bookingService, $this->createMock(LoggerInterface::class), tokenValid: false);
$controller = new TestableConfirmController($bookingService, $this->neverDispatchingBus(), $this->createMock(LoggerInterface::class), tokenValid: false);
$this->expectException(AccessDeniedException::class);
@@ -70,7 +81,7 @@ class ConfirmControllerTest extends TestCase
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('confirmBooking');
$controller = new TestableConfirmController($bookingService, $this->createMock(LoggerInterface::class));
$controller = new TestableConfirmController($bookingService, $this->neverDispatchingBus(), $this->createMock(LoggerInterface::class));
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/confirm', 'POST'));
@@ -97,7 +108,7 @@ class ConfirmControllerTest extends TestCase
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('confirmBooking');
$controller = new TestableConfirmController($bookingService, $this->createMock(LoggerInterface::class));
$controller = new TestableConfirmController($bookingService, $this->neverDispatchingBus(), $this->createMock(LoggerInterface::class));
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/confirm', 'POST'));
@@ -105,6 +116,17 @@ class ConfirmControllerTest extends TestCase
self::assertStringContainsString('app_admin_accommodationbooking_edit', (string) $response->headers->get('HX-Redirect'));
}
/**
* @return MessageBusInterface&MockObject
*/
private function neverDispatchingBus(): MessageBusInterface
{
$messageBus = $this->createMock(MessageBusInterface::class);
$messageBus->expects(self::never())->method('dispatch');
return $messageBus;
}
private function receivedBooking(): AccommodationBooking
{
$booking = new AccommodationBooking();
@@ -125,10 +147,11 @@ final class TestableConfirmController extends ConfirmController
public function __construct(
AccommodationBookingService $bookingService,
MessageBusInterface $messageBus,
LoggerInterface $logger,
private readonly bool $tokenValid = true,
) {
parent::__construct($bookingService, $logger);
parent::__construct($bookingService, $messageBus, $logger);
}
protected function isCsrfTokenValid(string $id, #[\SensitiveParameter] ?string $token): bool
@@ -1,146 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Tests\Controller\Admin\AccommodationBooking;
use App\Controller\Admin\AccommodationBooking\GenerateAccessLinkController;
use App\Entity\Groups\AccommodationBooking;
use App\Enum\Groups\AccommodationBookingStatus;
use App\Service\AccommodationBookingService;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Covers the guards around issuing an access link — the issuing itself is tested in
* AccommodationBookingServiceTest.
*/
class GenerateAccessLinkControllerTest extends TestCase
{
public function testGetRendersTheConfirmationModal(): void
{
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('regenerateAccessLink');
$controller = new TestableGenerateAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
$response = $controller->index($this->openBooking(), Request::create('/admin/accommodation-booking/1/generate-access-link'));
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
self::assertSame('admin/accommodation_booking/modal_generate_access_link.html.twig', $controller->renderedView);
}
public function testPostGeneratesTheLinkAndRedirectsTheBrowser(): void
{
$booking = $this->openBooking();
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::once())->method('regenerateAccessLink')->with($booking);
$controller = new TestableGenerateAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/generate-access-link', 'POST'));
self::assertTrue($response->headers->has('HX-Redirect'));
}
/**
* A draft is the office's own workbench: nothing has been offered, so a link would
* point the customer at a half-prepared record.
*
* @dataProvider requestMethods
*/
public function testADraftGetsNoAccessLinkAtAll(string $method): void
{
$booking = $this->openBooking();
$booking->setStatus(AccommodationBookingStatus::Draft);
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('regenerateAccessLink');
$controller = new TestableGenerateAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/generate-access-link', $method));
self::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
self::assertNull($controller->renderedView, 'not even the modal offering the action');
}
/**
* @return iterable<string, array{string}>
*/
public static function requestMethods(): iterable
{
yield 'GET' => [Request::METHOD_GET];
yield 'POST' => [Request::METHOD_POST];
}
public function testPostWithAnInvalidTokenIsDenied(): void
{
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('regenerateAccessLink');
$controller = new TestableGenerateAccessLinkController($bookingService, $this->createMock(LoggerInterface::class), tokenValid: false);
$this->expectException(AccessDeniedException::class);
$controller->index($this->openBooking(), Request::create('/admin/accommodation-booking/1/generate-access-link', 'POST'));
}
private function openBooking(): AccommodationBooking
{
$booking = new AccommodationBooking();
$booking->setStatus(AccommodationBookingStatus::Open);
$booking->setGroupName('Schulklasse 7b');
$booking->setEmail('[email protected]');
return $booking;
}
}
final class TestableGenerateAccessLinkController extends GenerateAccessLinkController
{
public ?string $renderedView = null;
/** @var list<array{type: string, message: mixed}> */
public array $flashes = [];
public function __construct(
AccommodationBookingService $bookingService,
LoggerInterface $logger,
private readonly bool $tokenValid = true,
) {
parent::__construct($bookingService, $logger);
}
protected function isCsrfTokenValid(string $id, #[\SensitiveParameter] ?string $token): bool
{
return $this->tokenValid;
}
/**
* @param array<string, mixed> $parameters
*/
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
{
$this->renderedView = $view;
return new Response();
}
protected function addFlash(string $type, mixed $message): void
{
$this->flashes[] = ['type' => $type, 'message' => $message];
}
/**
* @param array<string, mixed> $parameters
*/
protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string
{
return '/'.$route.'?'.http_build_query($parameters);
}
}
@@ -23,7 +23,7 @@ class SendAccessLinkControllerTest extends TestCase
public function testGetRendersTheConfirmationModal(): void
{
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
$bookingService->expects(self::never())->method('sendAccessLink');
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
@@ -38,7 +38,7 @@ class SendAccessLinkControllerTest extends TestCase
$booking = $this->openBooking();
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::once())->method('sendCustomerConfirmationEmail')->with($booking);
$bookingService->expects(self::once())->method('sendAccessLink')->with($booking);
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
@@ -53,7 +53,7 @@ class SendAccessLinkControllerTest extends TestCase
$booking->setAccessLinkIssuedAt(null);
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
$bookingService->expects(self::never())->method('sendAccessLink');
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
@@ -74,7 +74,7 @@ class SendAccessLinkControllerTest extends TestCase
$booking->setStatus(AccommodationBookingStatus::Draft);
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
$bookingService->expects(self::never())->method('sendAccessLink');
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
@@ -96,7 +96,7 @@ class SendAccessLinkControllerTest extends TestCase
public function testPostWithAnInvalidTokenIsDenied(): void
{
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
$bookingService->expects(self::never())->method('sendAccessLink');
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class), tokenValid: false);
@@ -111,7 +111,7 @@ class SendAccessLinkControllerTest extends TestCase
$booking->setEmail(null);
$bookingService = $this->createMock(AccommodationBookingService::class);
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
$bookingService->expects(self::never())->method('sendAccessLink');
$controller = new TestableSendAccessLinkController($bookingService, $this->createMock(LoggerInterface::class));
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace App\Tests\Service;
namespace App\Tests\Mailjet;
use App\Service\MailjetApiClient;
use App\Mailjet\ApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class MailjetApiClientTest extends TestCase
class ApiClientTest extends TestCase
{
public function testChecksSubscriptionAgainstSuppliedListId(): void
{
@@ -37,7 +37,7 @@ class MailjetApiClientTest extends TestCase
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet = new ApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$subscribed = $mailjet->isSubscribed(' [email protected] ', 123);
@@ -70,7 +70,7 @@ class MailjetApiClientTest extends TestCase
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$mailjet = new ApiClient(
$client,
new NullLogger(),
'key',
@@ -134,7 +134,7 @@ class MailjetApiClientTest extends TestCase
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$mailjet = new ApiClient(
$client,
new NullLogger(),
'key',
@@ -166,7 +166,7 @@ class MailjetApiClientTest extends TestCase
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet = new ApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->upsertContact(' [email protected] ');
@@ -182,7 +182,7 @@ class MailjetApiClientTest extends TestCase
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet = new ApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->ensureSubscribed(' [email protected] ', 456);
@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace App\Tests\Service;
namespace App\Tests\Mailjet;
use App\Service\MailjetApiClient;
use App\Mailjet\ApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
@@ -33,7 +33,7 @@ class MailjetNewsletterWebhookClientTest extends TestCase
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet = new ApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$response = $mailjet->createEventCallbackUrl('unsub', 'https://my.ep-reisen.de/webhooks/mailjet/newsletter');
self::assertSame(456, $response['Data'][0]['ID']);
@@ -48,7 +48,7 @@ class MailjetNewsletterWebhookClientTest extends TestCase
return new MockResponse('', ['http_code' => 204]);
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet = new ApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->deleteEventCallbackUrl(456);
}
}
@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace App\Tests\MessageHandler;
use App\ClickUp\ApiClient;
use App\ClickUp\Exception\ClickUpException;
use App\Entity\Groups\Accommodation;
use App\Entity\Groups\AccommodationBooking;
use App\Message\CreateClickUpBookingTaskMessage;
use App\MessageHandler\CreateClickUpBookingTaskHandler;
use App\Repository\Groups\AccommodationBookingRepository;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
class CreateClickUpBookingTaskHandlerTest extends TestCase
{
public function testCreatesTheTaskAndMovesItIntoTheGroupsStatus(): void
{
$repository = $this->createMock(AccommodationBookingRepository::class);
$repository->method('find')->with(42)->willReturn($this->booking());
$client = $this->createMock(ApiClient::class);
$client->method('isConfigured')->willReturn(true);
$client->expects(self::once())
->method('createTaskFromTemplate')
->with('WIEN01 2026-08-20 Anna Müller')
->willReturn('abc123');
$client->expects(self::once())
->method('updateTaskStatus')
->with('abc123', CreateClickUpBookingTaskHandler::TASK_STATUS);
$this->handler($repository, $client)(new CreateClickUpBookingTaskMessage(42));
}
public function testAnUnconfiguredClientIsSkippedWithoutTouchingTheDatabase(): void
{
$repository = $this->createMock(AccommodationBookingRepository::class);
$repository->expects(self::never())->method('find');
$client = $this->createMock(ApiClient::class);
$client->method('isConfigured')->willReturn(false);
$client->expects(self::never())->method('createTaskFromTemplate');
$this->handler($repository, $client)(new CreateClickUpBookingTaskMessage(42));
}
public function testAVanishedBookingIsSkipped(): void
{
$repository = $this->createMock(AccommodationBookingRepository::class);
$repository->method('find')->willReturn(null);
$client = $this->createMock(ApiClient::class);
$client->method('isConfigured')->willReturn(true);
$client->expects(self::never())->method('createTaskFromTemplate');
$this->handler($repository, $client)(new CreateClickUpBookingTaskMessage(42));
}
/**
* @dataProvider incompleteBookings
*/
public function testABookingWithoutTheDataForATaskNameIsSkipped(callable $mutate): void
{
$booking = $this->booking();
$mutate($booking);
$repository = $this->createMock(AccommodationBookingRepository::class);
$repository->method('find')->willReturn($booking);
$client = $this->createMock(ApiClient::class);
$client->method('isConfigured')->willReturn(true);
$client->expects(self::never())->method('createTaskFromTemplate');
$this->handler($repository, $client)(new CreateClickUpBookingTaskMessage(42));
}
/**
* @return iterable<string, array{callable(AccommodationBooking): void}>
*/
public static function incompleteBookings(): iterable
{
yield 'without an accommodation' => [static fn (AccommodationBooking $b) => $b->setAccommodation(null)];
yield 'without a contact name' => [static function (AccommodationBooking $b): void {
$b->setFirstName(null);
$b->setLastName(null);
}];
yield 'with a blank contact name' => [static function (AccommodationBooking $b): void {
$b->setFirstName(' ');
$b->setLastName(' ');
}];
}
public function testAFailingStatusUpdateDoesNotRetryTheTaskCreation(): void
{
$repository = $this->createMock(AccommodationBookingRepository::class);
$repository->method('find')->willReturn($this->booking());
$client = $this->createMock(ApiClient::class);
$client->method('isConfigured')->willReturn(true);
$client->method('createTaskFromTemplate')->willReturn('abc123');
$client->method('updateTaskStatus')->willThrowException(new ClickUpException('boom'));
$this->handler($repository, $client)(new CreateClickUpBookingTaskMessage(42));
// Reaching this point is the assertion: the exception must not bubble up into the
// transport, because a retry would create a second ClickUp task.
self::assertTrue(true);
}
private function handler(
AccommodationBookingRepository $repository,
ApiClient $client,
): CreateClickUpBookingTaskHandler {
return new CreateClickUpBookingTaskHandler($repository, $client, new NullLogger());
}
private function booking(): AccommodationBooking
{
$accommodation = new Accommodation();
$accommodation->setCalendarCode('WIEN01');
$booking = new AccommodationBooking();
$booking->setAccommodation($accommodation);
$booking->setDateFrom(new \DateTimeImmutable('2026-08-20'));
$booking->setFirstName('Anna');
$booking->setLastName('Müller');
return $booking;
}
}
@@ -245,8 +245,10 @@ class AccommodationBookingServiceTest extends TestCase
$service->sendCustomerConfirmationEmail($booking);
}
public function testRegenerateAccessLinkOverwritesAccessLinkIssuedAt(): void
public function testSendAccessLinkRefreshesTheLinkBeforeSending(): void
{
// The mail is the only way a link reaches the customer, so every send hands out a
// link that is good for another full TTL — the previous one stops working.
$booking = new AccommodationBooking();
$booking->setEmail('[email protected]');
$booking->setStatus(AccommodationBookingStatus::Open);
@@ -260,7 +262,7 @@ class AccommodationBookingServiceTest extends TestCase
$breakdownCalculator->method('compute')->willReturn(null);
$mailer = $this->createMock(Mailer::class);
$mailer->expects(self::never())->method('createAndSendEmail');
$mailer->expects(self::once())->method('createAndSendEmail');
$service = $this->createServiceWithAccommodation(
entityManager: $entityManager,
@@ -268,9 +270,28 @@ class AccommodationBookingServiceTest extends TestCase
breakdownCalculator: $breakdownCalculator,
);
$service->regenerateAccessLink($booking);
$service->sendAccessLink($booking);
self::assertNotSame($previousIssuedAt, $booking->getAccessLinkIssuedAt());
self::assertGreaterThan($previousIssuedAt, $booking->getAccessLinkIssuedAt());
}
public function testSendAccessLinkNoOpsForADraft(): void
{
$booking = new AccommodationBooking();
$booking->setEmail('[email protected]');
$booking->setStatus(AccommodationBookingStatus::Draft);
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects(self::never())->method('flush');
$mailer = $this->createMock(Mailer::class);
$mailer->expects(self::never())->method('createAndSendEmail');
$service = $this->createServiceWithAccommodation(entityManager: $entityManager, mailer: $mailer);
$service->sendAccessLink($booking);
self::assertNull($booking->getAccessLinkIssuedAt());
}
public function testADraftGetsNoAccessLinkGenerated(): void
@@ -287,7 +308,6 @@ class AccommodationBookingServiceTest extends TestCase
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
$service->issueAccessLink($booking);
$service->regenerateAccessLink($booking);
self::assertNull($booking->getAccessLinkIssuedAt());
}
+10 -2
View File
@@ -23,7 +23,11 @@ class CmsDataProviderTest extends TestCase
'room_types' => '<p>Zimmer</p>',
'additional_information' => '<p>Weitere Infos</p>',
'images' => ['resized' => ['l' => [['url' => 'l.jpg', 'alt' => 'Alt']]]],
'icons' => ['sauna' => ['label' => 'Sauna', 'value' => true]],
'icons' => [
['icon' => 'bed', 'label' => '69 Betten'],
['icon' => 'wifi', 'label' => 'WiFi'],
['icon' => 'sauna', 'label' => false],
],
'region' => [
'name' => 'Alpenregion',
'latitude' => 47.1,
@@ -50,7 +54,11 @@ class CmsDataProviderTest extends TestCase
self::assertSame("Musterstraße 1\n1234 Musterort", $data->address);
self::assertSame('<p>Zimmer</p>', $data->roomTypes);
self::assertSame('<p>Weitere Infos</p>', $data->additionalInformation);
self::assertSame(['sauna' => ['label' => 'Sauna', 'value' => true]], $data->icons);
self::assertSame([
['icon' => 'bed', 'label' => '69 Betten'],
['icon' => 'wifi', 'label' => 'WiFi'],
['icon' => 'sauna', 'label' => false],
], $data->icons);
self::assertNotNull($data->region);
self::assertSame('Alpenregion', $data->region->name);
self::assertSame('<p>Skigebiet</p>', $data->region->skiArea);
+18 -18
View File
@@ -8,11 +8,11 @@ use App\Email\Mailer;
use App\Entity\NewsletterConsent;
use App\Entity\NewsletterOptInRequest;
use App\Exception\NewsletterListNotAllowedException;
use App\Mailjet\ApiClient;
use App\Model\NewsletterConfirmationResult;
use App\Model\NewsletterSubscriptionRequestResult;
use App\Repository\NewsletterConsentRepository;
use App\Repository\NewsletterOptInRequestRepository;
use App\Service\MailjetApiClient;
use App\Service\NewsletterManager;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
@@ -26,7 +26,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -83,7 +83,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -114,7 +114,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -147,7 +147,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -191,7 +191,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -219,7 +219,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -251,7 +251,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -276,7 +276,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('ensureSubscribed');
@@ -303,7 +303,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('ensureSubscribed');
@@ -339,7 +339,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
@@ -370,7 +370,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
@@ -434,17 +434,17 @@ class NewsletterManagerTest extends TestCase
/**
* @param MockObject&NewsletterOptInRequestRepository $repository
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&MailjetApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&ApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
*/
private function createManager(
NewsletterOptInRequestRepository $repository,
NewsletterConsentRepository $consents,
EntityManagerInterface $entityManager,
MailjetApiClient $mailjet,
ApiClient $mailjet,
Mailer $mailer,
array $mailjetLists = [
10321569 => 'E&P Newsletter',