Skip to content

Commit 2d9f46b

Browse files
committed
Add tests
1 parent 2750b1e commit 2d9f46b

29 files changed

+1434
-24
lines changed

src/Domain/Messaging/Command/ProcessBouncesCommand.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#[AsCommand(name: 'phplist:bounces:process', description: 'Process bounce mailbox')]
2222
class ProcessBouncesCommand extends Command
2323
{
24+
private const IMAP_NOT_AVAILABLE = 'PHP IMAP extension not available. Falling back to Webklex IMAP.';
25+
private const FORCE_LOCK_FAILED = 'Could not apply force lock. Aborting.';
26+
private const ALREADY_LOCKED = 'Another bounce processing is already running. Aborting.';
27+
2428
protected function configure(): void
2529
{
2630
$this
@@ -53,16 +57,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5357
$inputOutput = new SymfonyStyle($input, $output);
5458

5559
if (!function_exists('imap_open')) {
56-
$inputOutput->note('PHP IMAP extension not available. Falling back to Webklex IMAP where applicable.');
60+
$inputOutput->note(self::IMAP_NOT_AVAILABLE);
5761
}
5862

5963
$force = (bool)$input->getOption('force');
6064
$lock = $this->lockService->acquirePageLock('bounce_processor', $force);
6165

62-
if (!$lock) {
63-
$inputOutput->warning('Another bounce processing is already running. Aborting.');
66+
if (($lock ?? 0) === 0) {
67+
$inputOutput->warning($force ? self::FORCE_LOCK_FAILED : self::ALREADY_LOCKED);
6468

65-
return Command::SUCCESS;
69+
return $force ? Command::FAILURE : Command::SUCCESS;
6670
}
6771

6872
try {
@@ -71,14 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7175

7276
$downloadReport = '';
7377

74-
$processor = null;
75-
foreach ($this->protocolProcessors as $p) {
76-
if ($p->getProtocol() === $protocol) {
77-
$processor = $p;
78-
break;
79-
}
80-
}
81-
78+
$processor = $this->findProcessorFor($protocol);
8279
if ($processor === null) {
8380
$inputOutput->error('Unsupported protocol: '.$protocol);
8481

@@ -103,4 +100,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103100
$this->lockService->release($lock);
104101
}
105102
}
103+
104+
private function findProcessorFor(string $protocol): ?BounceProtocolProcessor
105+
{
106+
foreach ($this->protocolProcessors as $processor) {
107+
if ($processor->getProtocol() === $protocol) {
108+
return $processor;
109+
}
110+
}
111+
112+
return null;
113+
}
106114
}

src/Domain/Messaging/Service/BounceActionResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function handle(string $action, array $context): void
5555
private function find(string $action): ?BounceActionHandlerInterface
5656
{
5757
foreach ($this->handlers as $handler) {
58-
if ($handler::supports($action)) {
58+
if ($handler->supports($action)) {
5959
return $handler;
6060
}
6161
}

src/Domain/Messaging/Service/Handler/BlacklistEmailAndDeleteBounceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
$this->blacklistService = $blacklistService;
2525
}
2626

27-
public static function supports(string $action): bool
27+
public function supports(string $action): bool
2828
{
2929
return $action === 'blacklistemailanddeletebounce';
3030
}

src/Domain/Messaging/Service/Handler/BlacklistEmailHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
$this->blacklistService = $blacklistService;
2121
}
2222

23-
public static function supports(string $action): bool
23+
public function supports(string $action): bool
2424
{
2525
return $action === 'blacklistemail';
2626
}

src/Domain/Messaging/Service/Handler/BlacklistUserAndDeleteBounceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
$this->blacklistService = $blacklistService;
2525
}
2626

27-
public static function supports(string $action): bool
27+
public function supports(string $action): bool
2828
{
2929
return $action === 'blacklistuseranddeletebounce';
3030
}

src/Domain/Messaging/Service/Handler/BlacklistUserHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
$this->blacklistService = $blacklistService;
2121
}
2222

23-
public static function supports(string $action): bool
23+
public function supports(string $action): bool
2424
{
2525
return $action === 'blacklistuser';
2626
}

src/Domain/Messaging/Service/Handler/BounceActionHandlerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
interface BounceActionHandlerInterface
88
{
9-
public static function supports(string $action): bool;
9+
public function supports(string $action): bool;
1010
public function handle(array $closureData): void;
1111
}

src/Domain/Messaging/Service/Handler/DecreaseCountConfirmUserAndDeleteBounceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
$this->subscriberRepository = $subscriberRepository;
2929
}
3030

31-
public static function supports(string $action): bool
31+
public function supports(string $action): bool
3232
{
3333
return $action === 'decreasecountconfirmuseranddeletebounce';
3434
}

src/Domain/Messaging/Service/Handler/DeleteBounceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct(BounceManager $bounceManager)
1515
$this->bounceManager = $bounceManager;
1616
}
1717

18-
public static function supports(string $action): bool
18+
public function supports(string $action): bool
1919
{
2020
return $action === 'deletebounce';
2121
}

src/Domain/Messaging/Service/Handler/DeleteUserAndBounceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(BounceManager $bounceManager, SubscriberManager $sub
1818
$this->subscriberManager = $subscriberManager;
1919
}
2020

21-
public static function supports(string $action): bool
21+
public function supports(string $action): bool
2222
{
2323
return $action === 'deleteuserandbounce';
2424
}

0 commit comments

Comments
 (0)