-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGetMessageRetriesCountServiceTest.php
59 lines (44 loc) · 2.04 KB
/
GetMessageRetriesCountServiceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types = 1);
namespace RunAsRoot\MessageQueueRetry\Test\Unit\Service;
use Magento\Framework\MessageQueue\Envelope;
use PhpAmqpLib\Wire\AMQPTable;
use PHPUnit\Framework\TestCase;
use RunAsRoot\MessageQueueRetry\Service\GetMessageRetriesCountService;
final class GetMessageRetriesCountServiceTest extends TestCase
{
private GetMessageRetriesCountService $sut;
protected function setUp(): void
{
$this->sut = new GetMessageRetriesCountService();
}
public function testItGetsMessageRetriesCount(): void
{
$testRetriesCount = 3;
$messageMock = $this->createMock(Envelope::class);
$applicationHeaders = new AMQPTable(['x-death' => [['count' => $testRetriesCount]]]);
$topicName = 'sample_topic';
$messageProperties = ['application_headers' => $applicationHeaders, 'topic_name' => $topicName];
$messageMock->expects($this->once())->method('getProperties')->willReturn($messageProperties);
$retriesCount = $this->sut->execute($messageMock);
$this->assertEquals($testRetriesCount, $retriesCount);
}
public function testItReturnsZeroAfterFirstProcessingBecauseItIsNotRetry(): void
{
$messageMock = $this->createMock(Envelope::class);
$messageProperties = [ ];
$messageMock->expects($this->once())->method('getProperties')->willReturn($messageProperties);
$retriesCount = $this->sut->execute($messageMock);
$this->assertEquals(0, $retriesCount);
}
public function testItReturnsZeroAsFallback(): void
{
$messageMock = $this->createMock(Envelope::class);
$applicationHeaders = new AMQPTable(['x-death' => [['count' => null]]]);
$topicName = 'sample_topic';
$messageProperties = ['application_headers' => $applicationHeaders, 'topic_name' => $topicName];
$messageMock->expects($this->once())->method('getProperties')->willReturn($messageProperties);
$retriesCount = $this->sut->execute($messageMock);
$this->assertEquals(0, $retriesCount);
}
}