Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/client-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:

jobs:
generate-openapi:
if: (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')) || (github.event_name == 'pull_request' && github.base_ref == 'main')
runs-on: ubuntu-22.04
outputs:
source_branch: ${{ steps.branch.outputs.source_branch }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/front-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- main
jobs:
generate-openapi:
if: (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')) || (github.event_name == 'pull_request' && github.base_ref == 'main')
runs-on: ubuntu-22.04
outputs:
source_branch: ${{ steps.branch.outputs.source_branch }}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"require": {
"php": "^8.1",
"phplist/core": "dev-dev",
"elasticsearch/elasticsearch": "^8.9",
"friendsofsymfony/rest-bundle": "*",
"symfony/test-pack": "^1.0",
"symfony/process": "^6.4",
Expand Down
8 changes: 4 additions & 4 deletions src/Messaging/Controller/BounceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Model\Bounce;
use PhpList\Core\Domain\Messaging\Repository\BounceRepository;
use PhpList\Core\Domain\Messaging\Repository\UserMessageBounceRepository;
use PhpList\Core\Domain\Messaging\Repository\Interfaces\UserMessageBounceReportReaderInterface;
use PhpList\Core\Domain\Identity\Service\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
Expand All @@ -34,7 +34,7 @@ public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly BounceNormalizer $normalizer,
private readonly PaginatedDataProvider $paginatedProvider,
private readonly UserMessageBounceRepository $userMessageBounceRepository
private readonly UserMessageBounceReportReaderInterface $userMessageBounceReportReader
) {
parent::__construct($authentication, $validator);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public function getBounceCountsByCampaign(Request $request): JsonResponse
$authUser = $this->requireAuthentication($request);

return $this->json(
data: $this->userMessageBounceRepository->getCampaignBounceTotals($authUser->getId()),
data: $this->userMessageBounceReportReader->getCampaignBounceTotals($authUser->getId()),
status: Response::HTTP_OK
);
}
Expand Down Expand Up @@ -263,7 +263,7 @@ public function getBounceCountsBySubscriber(Request $request): JsonResponse
$authUser = $this->requireAuthentication($request);

return $this->json(
data: $this->userMessageBounceRepository->getListBounceTotals($authUser->getId()),
data: $this->userMessageBounceReportReader->getListBounceTotals($authUser->getId()),
status: Response::HTTP_OK
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Subscription/Serializer/SubscriberHistoryNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace PhpList\RestBundle\Subscription\Serializer;

use DateTimeInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Subscription\Model\SubscriberHistory;
use PhpList\Core\Domain\Subscription\Model\Interfaces\SubscriberHistoryRecordInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

#[OA\Schema(
Expand All @@ -32,14 +33,14 @@ class SubscriberHistoryNormalizer implements NormalizerInterface
*/
public function normalize($object, string $format = null, array $context = []): array
{
if (!$object instanceof SubscriberHistory) {
if (!$object instanceof SubscriberHistoryRecordInterface) {
return [];
}

return [
'id' => $object->getId(),
'ip' => $object->getIp(),
'created_at' => $object->getCreatedAt()->format(\DateTimeInterface::ATOM),
'created_at' => $object->getCreatedAt()->format(DateTimeInterface::ATOM),
'summary' => $object->getSummary(),
'detail' => $object->getDetail(),
'system_info' => $object->getSystemInfo(),
Expand All @@ -51,7 +52,7 @@ public function normalize($object, string $format = null, array $context = []):
*/
public function supportsNormalization($data, string $format = null): bool
{
return $data instanceof SubscriberHistory;
return $data instanceof SubscriberHistoryRecordInterface;
}

/**
Expand All @@ -60,7 +61,7 @@ public function supportsNormalization($data, string $format = null): bool
public function getSupportedTypes(?string $format): array
{
return [
SubscriberHistory::class => true,
SubscriberHistoryRecordInterface::class => true,
];
}
}
4 changes: 2 additions & 2 deletions src/Subscription/Serializer/SubscriberNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use DateTimeInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Subscription\Model\Interfaces\SubscriberHistoryRecordInterface;
use PhpList\Core\Domain\Subscription\Model\Subscriber;
use PhpList\Core\Domain\Subscription\Model\SubscriberHistory;
use PhpList\Core\Domain\Subscription\Model\Subscription;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand Down Expand Up @@ -80,7 +80,7 @@ public function normalize($object, string $format = null, array $context = []):
'subscribed_lists' => array_map(function (Subscription $subscription) {
return $this->subscriberListNormalizer->normalize($subscription->getSubscriberList());
}, $object->getSubscriptions()->toArray()),
'history' => array_map(function (SubscriberHistory $history) {
'history' => array_map(function (SubscriberHistoryRecordInterface $history) {
return $this->subscriberHistoryNormalizer->normalize($history);
}, $object->getHistory()),
];
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/Messaging/Controller/BounceControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,32 @@ public function testDeleteWithValidIdReturnsNoContentAndRemovesBounce(): void
$this->entityManager->clear();
self::assertNull($this->entityManager->getRepository(Bounce::class)->find($bounceId));
}

public function testGetBounceCountsByCampaignWithoutSessionKeyReturnsUnauthorized(): void
{
self::getClient()->request('GET', '/api/v2/bounces/by/campaign');
$this->assertHttpUnauthorized();
}

public function testGetBounceCountsByCampaignWithValidSessionKeyReturnsArray(): void
{
// Regression check for wiring BounceController to UserMessageBounceReportReaderInterface
// (Elasticsearch-backed by default) - exercises the real service graph end to end.
$this->authenticatedJsonRequest('GET', '/api/v2/bounces/by/campaign');
$this->assertHttpOkay();
Comment thread
TatevikGr marked this conversation as resolved.
}

public function testGetBounceCountsBySubscriberWithoutSessionKeyReturnsUnauthorized(): void
{
self::getClient()->request('GET', '/api/v2/bounces/by/subscriber');
$this->assertHttpUnauthorized();
}

public function testGetBounceCountsBySubscriberWithValidSessionKeyReturnsArray(): void
{
// Regression check for wiring BounceController to UserMessageBounceReportReaderInterface
// (Elasticsearch-backed by default) - exercises the real service graph end to end.
$this->authenticatedJsonRequest('GET', '/api/v2/bounces/by/subscriber');
$this->assertHttpOkay();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testValidateSkipsConflictIfSameAdministrator(): void

$context = $this->createMock(ExecutionContextInterface::class);
$dto = new class {
public $updatingId = 1;
public int $updatingId = 1;
};

$context->method('getObject')->willReturn($dto);
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/Subscription/Serializer/SubscriberNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use PhpList\Core\Domain\Subscription\Model\ReadModel\SubscriberHistoryReadModel;
use PhpList\Core\Domain\Subscription\Model\Subscriber;
use PhpList\Core\Domain\Subscription\Model\SubscriberList;
use PhpList\Core\Domain\Subscription\Model\Subscription;
Expand Down Expand Up @@ -91,4 +92,47 @@ public function testNormalizeWithInvalidObject(): void
$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer(), new SubscriberHistoryNormalizer());
$this->assertSame([], $normalizer->normalize(new stdClass()));
}

public function testNormalizeAcceptsElasticsearchBackedHistoryReadModels(): void
{
$history = new SubscriberHistoryReadModel(
id: 7,
subscriberId: 101,
ip: '127.0.0.1',
createdAt: new DateTime('2025-02-01T00:00:00+00:00'),
summary: 'Updated',
detail: 'Detail',
systemInfo: 'Info',
);

$subscriber = $this->createMock(Subscriber::class);
$subscriber->method('getId')->willReturn(101);
$subscriber->method('getEmail')->willReturn('test@example.com');
$subscriber->method('getCreatedAt')->willReturn(new DateTime('2024-12-31T12:00:00+00:00'));
$subscriber->method('getUpdatedAt')->willReturn(new DateTime('2024-12-31T12:00:00+00:00'));
$subscriber->method('isConfirmed')->willReturn(true);
$subscriber->method('isBlacklisted')->willReturn(false);
$subscriber->method('getBounceCount')->willReturn(0);
$subscriber->method('getUniqueId')->willReturn('abc123');
$subscriber->method('getUuid')->willReturn('abc-123-abc-123');
$subscriber->method('hasHtmlEmail')->willReturn(true);
$subscriber->method('isDisabled')->willReturn(false);
$subscriber->method('getSubscriptions')->willReturn(new ArrayCollection([]));
$subscriber->method('getHistory')->willReturn([$history]);

$normalizer = new SubscriberNormalizer(new SubscriberListNormalizer(), new SubscriberHistoryNormalizer());

$result = $normalizer->normalize($subscriber);

$this->assertSame([
[
'id' => 7,
'ip' => '127.0.0.1',
'created_at' => '2025-02-01T00:00:00+00:00',
'summary' => 'Updated',
'detail' => 'Detail',
'system_info' => 'Info',
],
], $result['history']);
}
}
Loading