7
7
use Magento \Framework \MessageQueue \Envelope ;
8
8
use PHPUnit \Framework \MockObject \MockObject ;
9
9
use PHPUnit \Framework \TestCase ;
10
+ use RunAsRoot \MessageQueueRetry \Repository \Query \FindQueueRetryLimitByTopicNameQuery ;
10
11
use RunAsRoot \MessageQueueRetry \Service \GetMessageRetriesCountService ;
11
12
use RunAsRoot \MessageQueueRetry \Service \IsMessageShouldBeSavedForRetryService ;
12
13
use RunAsRoot \MessageQueueRetry \System \Config \MessageQueueRetryConfig ;
@@ -16,27 +17,29 @@ final class IsMessageShouldBeSavedForRetryServiceTest extends TestCase
16
17
private IsMessageShouldBeSavedForRetryService $ sut ;
17
18
private MessageQueueRetryConfig |MockObject $ messageQueueRetryConfigMock ;
18
19
private GetMessageRetriesCountService |MockObject $ getMessageRetriesCountServiceMock ;
20
+ private FindQueueRetryLimitByTopicNameQuery |MockObject $ findQueueRetryLimitByTopicNameQueryMock ;
19
21
20
22
protected function setUp (): void
21
23
{
22
24
$ this ->messageQueueRetryConfigMock = $ this ->createMock (MessageQueueRetryConfig::class);
23
25
$ this ->getMessageRetriesCountServiceMock = $ this ->createMock (GetMessageRetriesCountService::class);
24
-
25
- $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
26
+ $ this ->findQueueRetryLimitByTopicNameQueryMock = $ this ->createMock (FindQueueRetryLimitByTopicNameQuery::class);
26
27
27
28
$ this ->sut = new IsMessageShouldBeSavedForRetryService (
28
29
$ this ->messageQueueRetryConfigMock ,
29
- $ this ->getMessageRetriesCountServiceMock
30
+ $ this ->getMessageRetriesCountServiceMock ,
31
+ $ this ->findQueueRetryLimitByTopicNameQueryMock
30
32
);
31
33
}
32
34
33
35
public function testItReturnsTrueIfRetryLimitIsReached (): void
34
36
{
35
37
$ testMessageProperties = ['topic_name ' => 'sample_topic ' ];
36
- $ testQueueConfiguration = ['sample_topic ' => ['retry_limit ' => 2 ]];
37
38
39
+ $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
38
40
$ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (2 );
39
- $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())->method ('getDelayQueues ' )->willReturn ($ testQueueConfiguration );
41
+ $ this ->findQueueRetryLimitByTopicNameQueryMock ->expects ($ this ->once ())->method ('execute ' )
42
+ ->with ('sample_topic ' )->willReturn (2 );
40
43
41
44
$ result = $ this ->sut ->execute (new Envelope ('' , $ testMessageProperties ));
42
45
$ this ->assertTrue ($ result );
@@ -45,10 +48,11 @@ public function testItReturnsTrueIfRetryLimitIsReached(): void
45
48
public function testItReturnsFalseIfRetryLimitIsNotReached (): void
46
49
{
47
50
$ testMessageProperties = ['topic_name ' => 'sample_topic ' ];
48
- $ testQueueConfiguration = ['sample_topic ' => ['retry_limit ' => 2 ]];
49
51
52
+ $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
50
53
$ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (1 );
51
- $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())->method ('getDelayQueues ' )->willReturn ($ testQueueConfiguration );
54
+ $ this ->findQueueRetryLimitByTopicNameQueryMock ->expects ($ this ->once ())->method ('execute ' )
55
+ ->with ('sample_topic ' )->willReturn (2 );
52
56
53
57
$ result = $ this ->sut ->execute (new Envelope ('' , $ testMessageProperties ));
54
58
$ this ->assertFalse ($ result );
@@ -57,29 +61,19 @@ public function testItReturnsFalseIfRetryLimitIsNotReached(): void
57
61
public function testItReturnsFalseIfQueueConfigHasNoRetryLimit (): void
58
62
{
59
63
$ testMessageProperties = ['topic_name ' => 'sample_topic ' ];
60
- $ testQueueConfiguration = ['sample_topic ' => []];
61
-
62
- $ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (1 );
63
- $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())->method ('getDelayQueues ' )->willReturn ($ testQueueConfiguration );
64
-
65
- $ result = $ this ->sut ->execute (new Envelope ('' , $ testMessageProperties ));
66
- $ this ->assertFalse ($ result );
67
- }
68
-
69
- public function testItReturnsFalseIfQueueIsNotConfigured (): void
70
- {
71
- $ testMessageProperties = ['topic_name ' => 'sample_topic ' ];
72
- $ testQueueConfiguration = ['another_topic ' => ['retry_limit ' => 1 ]];
73
64
65
+ $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
74
66
$ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (1 );
75
- $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())->method ('getDelayQueues ' )->willReturn ($ testQueueConfiguration );
67
+ $ this ->findQueueRetryLimitByTopicNameQueryMock ->expects ($ this ->once ())->method ('execute ' )
68
+ ->with ('sample_topic ' )->willReturn (null );
76
69
77
70
$ result = $ this ->sut ->execute (new Envelope ('' , $ testMessageProperties ));
78
71
$ this ->assertFalse ($ result );
79
72
}
80
73
81
74
public function testItReturnsFalseIfMessageHasNoTopicName (): void
82
75
{
76
+ $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
83
77
$ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (1 );
84
78
85
79
$ result = $ this ->sut ->execute (new Envelope ('' , []));
@@ -88,6 +82,7 @@ public function testItReturnsFalseIfMessageHasNoTopicName(): void
88
82
89
83
public function testItReturnsFalseIfItIsFirstTimeConsuming (): void
90
84
{
85
+ $ this ->messageQueueRetryConfigMock ->method ('isDelayQueueEnabled ' )->willReturn (true );
91
86
$ this ->getMessageRetriesCountServiceMock ->expects ($ this ->once ())->method ('execute ' )->willReturn (0 );
92
87
93
88
$ result = $ this ->sut ->execute (new Envelope ('' , []));
@@ -96,9 +91,7 @@ public function testItReturnsFalseIfItIsFirstTimeConsuming(): void
96
91
97
92
public function testItReturnsFalseIfConfigDisabled (): void
98
93
{
99
- $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())
100
- ->method ('isDelayQueueEnabled ' )
101
- ->willReturn (false );
94
+ $ this ->messageQueueRetryConfigMock ->expects ($ this ->once ())->method ('isDelayQueueEnabled ' )->willReturn (false );
102
95
103
96
$ result = $ this ->sut ->execute (new Envelope ('' , []));
104
97
$ this ->assertFalse ($ result );
0 commit comments