Skip to content

Commit

Permalink
[AdherentMessage] debug mailchimp campaign initialization (#8188)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Feb 15, 2023
1 parent c46d3e0 commit 5f241dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@

use App\Entity\AdherentMessage\AdherentMessageInterface;
use App\Entity\AdherentMessage\MailchimpCampaign;
use Psr\Log\LoggerInterface;

class GenericMailchimpCampaignHandler implements MailchimpCampaignHandlerInterface
{
public function __construct(private readonly LoggerInterface $logger)
{
}

public static function getPriority(): int
{
return -255;
}

public function handle(AdherentMessageInterface $message): void
{
$this->logger->error(sprintf('Message %d has %d Mailchimp campaigns', $message->getId(), \count($message->getMailchimpCampaigns())));

if (!\count($message->getMailchimpCampaigns())) {
$message->setMailchimpCampaigns([new MailchimpCampaign($message)]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
use App\Repository\AdherentMessageRepository;
use Doctrine\ORM\EntityManagerInterface as ObjectManager;
use Psr\Container\ContainerInterface;
use Psr\Log\NullLogger;
use Ramsey\Uuid\Uuid;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -429,7 +430,7 @@ public function testCandidateMessageGeneratesGoodPayloads(): void
$message = $this->preparedMessage(CandidateAdherentMessage::class);
$message->setFilter(new AdherentGeoZoneFilter(new Zone(Zone::DEPARTMENT, 'code1', 'Tag1')));

(new GenericMailchimpCampaignHandler())->handle($message);
$this->createGenericMailchimpCampaignHandler()->handle($message);

$this->clientMock
->expects($this->exactly(2))
Expand Down Expand Up @@ -492,7 +493,7 @@ public function testCandidateJecouteMessageGeneratesGoodPayloads(): void
$message = $this->preparedMessage(CandidateJecouteMessage::class);
$message->setFilter(new JecouteFilter(new Zone(Zone::DEPARTMENT, 'code1', 'Tag1')));

(new GenericMailchimpCampaignHandler())->handle($message);
$this->createGenericMailchimpCampaignHandler()->handle($message);

$this->clientMock
->expects($this->exactly(2))
Expand Down Expand Up @@ -551,7 +552,7 @@ public function testCoalitionsMessageGeneratesGoodPayloads(): void
$cause->setAuthor($this->adherentDummy);
$cause->setMailchimpId(123);

(new GenericMailchimpCampaignHandler())->handle($message);
$this->createGenericMailchimpCampaignHandler()->handle($message);

$this->clientMock
->expects($this->exactly(2))
Expand Down Expand Up @@ -615,7 +616,7 @@ public function testCorrespondentMessageGeneratesGoodPayloads(): void
$message = $this->preparedMessage(CorrespondentAdherentMessage::class);
$message->setFilter(new AdherentGeoZoneFilter(new Zone(Zone::DEPARTMENT, 'code1', 'Tag1')));

(new GenericMailchimpCampaignHandler())->handle($message);
$this->createGenericMailchimpCampaignHandler()->handle($message);

$this->clientMock
->expects($this->exactly(2))
Expand Down Expand Up @@ -665,7 +666,7 @@ public function testRegionalCoordinatorMessageGeneratesGoodPayloads(): void
$message = $this->preparedMessage(RegionalCoordinatorAdherentMessage::class);
$message->setFilter(new MessageFilter([new Zone(Zone::DEPARTMENT, 'code1', 'Tag1')]));

(new GenericMailchimpCampaignHandler())->handle($message);
$this->createGenericMailchimpCampaignHandler()->handle($message);

$this->clientMock
->expects($this->exactly(2))
Expand Down Expand Up @@ -889,6 +890,11 @@ private function createMockResponse(string $content, int $statusCode = 200): Res
'toArray' => json_decode($content, true),
]);
}

private function createGenericMailchimpCampaignHandler(): GenericMailchimpCampaignHandler
{
return new GenericMailchimpCampaignHandler(new NullLogger());
}
}

class SimpleContainer implements ContainerInterface
Expand Down

0 comments on commit 5f241dd

Please sign in to comment.