Skip to content

Commit 93547aa

Browse files
committed
Add test
1 parent 6932106 commit 93547aa

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

tests/Unit/Bounce/Command/ProcessBouncesCommandTest.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ProcessBouncesCommandTest extends TestCase
3030

3131
private CommandTester $commandTester;
3232
private TranslatorInterface|MockObject $translator;
33+
private EntityManagerInterface|MockObject $entityManager;
3334

3435
protected function setUp(): void
3536
{
@@ -40,6 +41,7 @@ protected function setUp(): void
4041
$this->unidentifiedReprocessor = $this->createMock(UnidentifiedBounceReprocessor::class);
4142
$this->consecutiveBounceHandler = $this->createMock(ConsecutiveBounceHandler::class);
4243
$this->translator = new Translator('en');
44+
$this->entityManager = $this->createMock(EntityManagerInterface::class);
4345

4446
$command = new ProcessBouncesCommand(
4547
lockService: $this->lockService,
@@ -49,7 +51,7 @@ protected function setUp(): void
4951
unidentifiedReprocessor: $this->unidentifiedReprocessor,
5052
consecutiveBounceHandler: $this->consecutiveBounceHandler,
5153
translator: $this->translator,
52-
entityManager: $this->createMock(EntityManagerInterface::class),
54+
entityManager: $this->entityManager,
5355
);
5456

5557
$this->commandTester = new CommandTester($command);
@@ -199,6 +201,67 @@ public function testForceOptionIsPassedToLockService(): void
199201
'--force' => true,
200202
]);
201203

204+
$this->assertSame(0, $this->commandTester->getStatusCode());
205+
}
206+
public function testForceLockFailureReturnsFailureAndMessage(): void
207+
{
208+
$this->lockService->expects($this->once())
209+
->method('acquirePageLock')
210+
->with('bounce_processor', true)
211+
->willReturn(0);
212+
213+
$this->protocolProcessor->expects($this->never())->method('process');
214+
$this->advancedRulesProcessor->expects($this->never())->method('process');
215+
$this->consecutiveBounceHandler->expects($this->never())->method('handle');
216+
217+
$this->commandTester->execute([
218+
'--force' => true,
219+
]);
220+
221+
$output = $this->commandTester->getDisplay();
222+
$this->assertStringContainsString('Could not apply force lock. Aborting.', $output);
223+
$this->assertSame(1, $this->commandTester->getStatusCode());
224+
}
225+
226+
public function testRulesBatchSizeOptionIsRespected(): void
227+
{
228+
$this->lockService
229+
->expects($this->once())
230+
->method('acquirePageLock')
231+
->with('bounce_processor', false)
232+
->willReturn(10);
233+
$this->lockService
234+
->expects($this->once())
235+
->method('release')
236+
->with(10);
237+
238+
$this->protocolProcessor->method('getProtocol')->willReturn('pop');
239+
$this->protocolProcessor->method('process')->willReturn('');
240+
241+
$this->advancedRulesProcessor
242+
->expects($this->once())
243+
->method('process')
244+
->with($this->anything(), 50);
245+
246+
$this->commandTester->execute([
247+
'--rules-batch-size' => 50,
248+
]);
249+
250+
$this->assertSame(0, $this->commandTester->getStatusCode());
251+
}
252+
253+
public function testEntityManagerIsFlushedAfterLockAcquireAttempt(): void
254+
{
255+
$this->lockService->expects($this->once())
256+
->method('acquirePageLock')
257+
->with('bounce_processor', false)
258+
->willReturn(null);
259+
260+
$this->entityManager->expects($this->once())
261+
->method('flush');
262+
263+
$this->commandTester->execute([]);
264+
202265
$this->assertSame(0, $this->commandTester->getStatusCode());
203266
}
204267
}

0 commit comments

Comments
 (0)