Skip to content

Commit b1ef842

Browse files
committed
AdvancedBounceRulesProcessor
1 parent fd4ef35 commit b1ef842

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

resources/translations/messages.en.xlf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258

259259
<trans-unit id="messaging.announce_processed_count">
260260
<source>Processed %processed% out of %total% bounces for advanced bounce rules</source>
261-
<source>Processed %processed% out of %total% bounces for advanced bounce rules</source>
261+
<target>Processed %processed% out of %total% bounces for advanced bounce rules</target>
262262
</trans-unit>
263263

264264
<trans-unit id="messaging.announce_processed_total">
@@ -270,6 +270,23 @@
270270
<target>%not_processed% bounces were not matched by advanced processing rules</target>
271271
</trans-unit>
272272

273+
<trans-unit id="messaging.opening_mbox">
274+
<source>Opening mbox %file%</source>
275+
<target>Opening mbox %file%</target>
276+
</trans-unit>
277+
<trans-unit id="messaging.connecting_to">
278+
<source>Connecting to %mailbox%</source>
279+
<target>Connecting to %mailbox%</target>
280+
</trans-unit>
281+
<trans-unit id="messaging.do_not_interrupt">
282+
<source>Please do not interrupt this process</source>
283+
<target>Please do not interrupt this process</target>
284+
</trans-unit>
285+
<trans-unit id="messaging.mbox_missing_option">
286+
<source>mbox file path must be provided with --mailbox.</source>
287+
<target>mbox file path must be provided with --mailbox.</target>
288+
</trans-unit>
289+
273290
<!-- Subscription -->
274291
<trans-unit id="subscription.list_not_found">
275292
<source>Subscriber list not found.</source>

src/Domain/Messaging/Service/Processor/MboxBounceProcessor.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
use RuntimeException;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Style\SymfonyStyle;
11+
use Symfony\Contracts\Translation\TranslatorInterface;
1112

1213
class MboxBounceProcessor implements BounceProtocolProcessor
1314
{
1415
private BounceProcessingServiceInterface $processingService;
16+
private TranslatorInterface $translator;
1517

16-
public function __construct(BounceProcessingServiceInterface $processingService)
18+
public function __construct(BounceProcessingServiceInterface $processingService, TranslatorInterface $translator)
1719
{
1820
$this->processingService = $processingService;
21+
$this->translator = $translator;
1922
}
2023

2124
public function getProtocol(): string
@@ -30,12 +33,12 @@ public function process(InputInterface $input, SymfonyStyle $inputOutput): strin
3033

3134
$file = (string)$input->getOption('mailbox');
3235
if (!$file) {
33-
$inputOutput->error('mbox file path must be provided with --mailbox.');
36+
$inputOutput->error($this->translator->trans('mbox file path must be provided with --mailbox.'));
3437
throw new RuntimeException('Missing --mailbox for mbox protocol');
3538
}
3639

37-
$inputOutput->section('Opening mbox ' . $file);
38-
$inputOutput->writeln('Please do not interrupt this process');
40+
$inputOutput->section($this->translator->trans('Opening mbox %file%', ['%file%' => $file]));
41+
$inputOutput->writeln($this->translator->trans('Please do not interrupt this process'));
3942

4043
return $this->processingService->processMailbox(
4144
mailbox: $file,

src/Domain/Messaging/Service/Processor/PopBounceProcessor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@
77
use PhpList\Core\Domain\Messaging\Service\BounceProcessingServiceInterface;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Style\SymfonyStyle;
10+
use Symfony\Contracts\Translation\TranslatorInterface;
1011

1112
class PopBounceProcessor implements BounceProtocolProcessor
1213
{
1314
private BounceProcessingServiceInterface $processingService;
1415
private string $host;
1516
private int $port;
1617
private string $mailboxNames;
18+
private TranslatorInterface $translator;
1719

1820
public function __construct(
1921
BounceProcessingServiceInterface $processingService,
2022
string $host,
2123
int $port,
22-
string $mailboxNames
24+
string $mailboxNames,
25+
TranslatorInterface $translator
2326
) {
2427
$this->processingService = $processingService;
2528
$this->host = $host;
2629
$this->port = $port;
2730
$this->mailboxNames = $mailboxNames;
31+
$this->translator = $translator;
2832
}
2933

3034
public function getProtocol(): string
@@ -44,8 +48,8 @@ public function process(InputInterface $input, SymfonyStyle $inputOutput): strin
4448
$mailboxName = 'INBOX';
4549
}
4650
$mailbox = sprintf('{%s:%s}%s', $this->host, $this->port, $mailboxName);
47-
$inputOutput->section('Connecting to ' . $mailbox);
48-
$inputOutput->writeln('Please do not interrupt this process');
51+
$inputOutput->section($this->translator->trans('Connecting to %mailbox%', ['%mailbox%' => $mailbox]));
52+
$inputOutput->writeln($this->translator->trans('Please do not interrupt this process'));
4953

5054
$downloadReport .= $this->processingService->processMailbox(
5155
mailbox: $mailbox,

tests/Unit/Domain/Messaging/Service/Processor/AdvancedBounceRulesProcessorTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,23 @@ protected function setUp(): void
3737

3838
public function testNoActiveRules(): void
3939
{
40-
$this->io->expects($this->once())->method('section')->with('Processing bounces based on active bounce rules');
40+
$translator = new Translator('en');
41+
$this->io
42+
->expects($this->once())
43+
->method('section')
44+
->with($translator->trans('Processing bounces based on active bounce rules'));
4145
$this->ruleManager->method('loadActiveRules')->willReturn([]);
42-
$this->io->expects($this->once())->method('writeln')->with('No active rules');
46+
$this->io
47+
->expects($this->once())
48+
->method('writeln')
49+
->with($translator->trans('No active rules'));
4350

4451
$processor = new AdvancedBounceRulesProcessor(
4552
bounceManager: $this->bounceManager,
4653
ruleManager: $this->ruleManager,
4754
actionResolver: $this->actionResolver,
4855
subscriberManager: $this->subscriberManager,
49-
translator: new Translator('en'),
56+
translator: $translator,
5057
);
5158

5259
$processor->process($this->io, 100);
@@ -161,18 +168,19 @@ public function testProcessingWithMatchesAndNonMatches(): void
161168
return null;
162169
});
163170

171+
$translator = new Translator('en');
164172
$this->io
165173
->expects($this->once())
166174
->method('section')
167-
->with('Processing bounces based on active bounce rules');
175+
->with($translator->trans('Processing bounces based on active bounce rules'));
168176
$this->io->expects($this->exactly(4))->method('writeln');
169177

170178
$processor = new AdvancedBounceRulesProcessor(
171179
bounceManager: $this->bounceManager,
172180
ruleManager: $this->ruleManager,
173181
actionResolver: $this->actionResolver,
174182
subscriberManager: $this->subscriberManager,
175-
translator: new Translator('en'),
183+
translator: $translator,
176184
);
177185

178186
$processor->process($this->io, 2);

tests/Unit/Domain/Messaging/Service/Processor/MboxBounceProcessorTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use RuntimeException;
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Style\SymfonyStyle;
14+
use Symfony\Component\Translation\Translator;
1415

1516
class MboxBounceProcessorTest extends TestCase
1617
{
@@ -27,13 +28,14 @@ protected function setUp(): void
2728

2829
public function testGetProtocol(): void
2930
{
30-
$processor = new MboxBounceProcessor($this->service);
31+
$processor = new MboxBounceProcessor($this->service, new Translator('en'));
3132
$this->assertSame('mbox', $processor->getProtocol());
3233
}
3334

3435
public function testProcessThrowsWhenMailboxMissing(): void
3536
{
36-
$processor = new MboxBounceProcessor($this->service);
37+
$translator = new Translator('en');
38+
$processor = new MboxBounceProcessor($this->service, $translator);
3739

3840
$this->input->method('getOption')->willReturnMap([
3941
['test', false],
@@ -44,7 +46,7 @@ public function testProcessThrowsWhenMailboxMissing(): void
4446
$this->io
4547
->expects($this->once())
4648
->method('error')
47-
->with('mbox file path must be provided with --mailbox.');
49+
->with($translator->trans('mbox file path must be provided with --mailbox.'));
4850

4951
$this->expectException(RuntimeException::class);
5052
$this->expectExceptionMessage('Missing --mailbox for mbox protocol');
@@ -54,16 +56,17 @@ public function testProcessThrowsWhenMailboxMissing(): void
5456

5557
public function testProcessSuccess(): void
5658
{
57-
$processor = new MboxBounceProcessor($this->service);
59+
$translator = new Translator('en');
60+
$processor = new MboxBounceProcessor($this->service, $translator);
5861

5962
$this->input->method('getOption')->willReturnMap([
6063
['test', true],
6164
['maximum', 50],
6265
['mailbox', '/var/mail/bounce.mbox'],
6366
]);
6467

65-
$this->io->expects($this->once())->method('section')->with('Opening mbox /var/mail/bounce.mbox');
66-
$this->io->expects($this->once())->method('writeln')->with('Please do not interrupt this process');
68+
$this->io->expects($this->once())->method('section')->with($translator->trans('Opening mbox %file%', ['%file%' => '/var/mail/bounce.mbox']));
69+
$this->io->expects($this->once())->method('writeln')->with($translator->trans('Please do not interrupt this process'));
6770

6871
$this->service->expects($this->once())
6972
->method('processMailbox')

tests/Unit/Domain/Messaging/Service/Processor/PopBounceProcessorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Style\SymfonyStyle;
13+
use Symfony\Component\Translation\Translator;
1314

1415
class PopBounceProcessorTest extends TestCase
1516
{
@@ -26,13 +27,14 @@ protected function setUp(): void
2627

2728
public function testGetProtocol(): void
2829
{
29-
$processor = new PopBounceProcessor($this->service, 'mail.example.com', 995, 'INBOX');
30+
$processor = new PopBounceProcessor($this->service, 'mail.example.com', 995, 'INBOX', new Translator('en'));
3031
$this->assertSame('pop', $processor->getProtocol());
3132
}
3233

3334
public function testProcessWithMultipleMailboxesAndDefaults(): void
3435
{
35-
$processor = new PopBounceProcessor($this->service, 'pop.example.com', 110, 'INBOX, ,Custom');
36+
$translator = new Translator('en');
37+
$processor = new PopBounceProcessor($this->service, 'pop.example.com', 110, 'INBOX, ,Custom', $translator);
3638

3739
$this->input->method('getOption')->willReturnMap([
3840
['test', true],

0 commit comments

Comments
 (0)