3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \MessageQueue \Model \Cron ;
7
9
10
+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
8
11
use Magento \Framework \App \DeploymentConfig ;
9
- use Magento \Framework \App \ResourceConnection ;
10
- use Magento \Framework \Lock \Backend \Database ;
11
- use Magento \Framework \MessageQueue \Consumer \ConfigInterface as ConsumerConfigInterface ;
12
- use Magento \Framework \Lock \LockManagerInterface ;
13
12
use Magento \Framework \App \DeploymentConfig \FileReader ;
14
13
use Magento \Framework \App \DeploymentConfig \Writer ;
14
+ use Magento \Framework \App \Filesystem \DirectoryList ;
15
+ use Magento \Framework \App \ResourceConnection ;
15
16
use Magento \Framework \Config \File \ConfigFilePool ;
16
- use Magento \Framework \ShellInterface ;
17
17
use Magento \Framework \Filesystem ;
18
- use Magento \Framework \App \Filesystem \DirectoryList ;
19
- use Magento \Framework \App \Config \ReinitableConfigInterface ;
18
+ use Magento \Framework \Lock \Backend \Database ;
19
+ use Magento \Framework \Lock \LockManagerInterface ;
20
+ use Magento \Framework \MessageQueue \Consumer \ConfigInterface as ConsumerConfigInterface ;
21
+ use Magento \Framework \ObjectManagerInterface ;
22
+ use Magento \Framework \ShellInterface ;
23
+ use Magento \TestFramework \Helper \Bootstrap ;
24
+ use PHPUnit \Framework \MockObject \MockObject ;
25
+ use PHPUnit \Framework \TestCase ;
20
26
21
27
/**
22
28
* Tests the different cases of consumers running by ConsumersRunner
23
29
*
24
- * {@inheritdoc}
25
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
31
*/
27
- class ConsumersRunnerTest extends \ PHPUnit \ Framework \ TestCase
32
+ class ConsumersRunnerTest extends TestCase
28
33
{
29
34
/**
30
- * @var \Magento\Framework\ ObjectManagerInterface
35
+ * @var ObjectManagerInterface
31
36
*/
32
37
private $ objectManager ;
33
38
@@ -69,7 +74,7 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
69
74
private $ appConfig ;
70
75
71
76
/**
72
- * @var ShellInterface|\PHPUnit\Framework\MockObject\ MockObject
77
+ * @var ShellInterface|MockObject
73
78
*/
74
79
private $ shellMock ;
75
80
@@ -83,7 +88,7 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
83
88
*/
84
89
protected function setUp (): void
85
90
{
86
- $ this ->objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
91
+ $ this ->objectManager = Bootstrap::getObjectManager ();
87
92
$ this ->shellMock = $ this ->getMockBuilder (ShellInterface::class)
88
93
->getMockForAbstractClass ();
89
94
$ resourceConnection = $ this ->objectManager ->create (ResourceConnection::class);
@@ -106,7 +111,7 @@ protected function setUp(): void
106
111
->willReturnCallback (
107
112
function ($ command , $ arguments ) {
108
113
$ command = vsprintf ($ command , $ arguments );
109
- $ params = \ Magento \ TestFramework \ Helper \ Bootstrap::getInstance ()->getAppInitParams ();
114
+ $ params = Bootstrap::getInstance ()->getAppInitParams ();
110
115
$ params ['MAGE_DIRS ' ]['base ' ]['path ' ] = BP ;
111
116
$ params = 'INTEGRATION_TEST_PARAMS=" ' . urldecode (http_build_query ($ params )) . '" ' ;
112
117
$ command = str_replace ('bin/magento ' , 'dev/tests/integration/bin/magento ' , $ command );
@@ -117,6 +122,52 @@ function ($command, $arguments) {
117
122
);
118
123
}
119
124
125
+ /**
126
+ * @param string $specificConsumer
127
+ * @param int $maxMessage
128
+ * @param string $command
129
+ * @param array $expectedArguments
130
+ *
131
+ * @return void
132
+ * @dataProvider runDataProvider
133
+ */
134
+ public function testArgumentMaxMessages (
135
+ string $ specificConsumer ,
136
+ int $ maxMessage ,
137
+ string $ command ,
138
+ array $ expectedArguments
139
+ ) {
140
+ $ config = $ this ->config ;
141
+ $ config ['cron_consumers_runner ' ] = ['consumers ' => [$ specificConsumer ], 'max_messages ' => $ maxMessage ];
142
+ $ this ->writeConfig ($ config );
143
+ $ this ->shellMock ->expects ($ this ->any ())
144
+ ->method ('execute ' )
145
+ ->with ($ command , $ expectedArguments );
146
+
147
+ $ this ->consumersRunner ->run ();
148
+ }
149
+
150
+ /**
151
+ * @return array
152
+ */
153
+ public function runDataProvider ()
154
+ {
155
+ return [
156
+ [
157
+ 'specificConsumer ' => 'exportProcessor ' ,
158
+ 'max_messages ' => 10 ,
159
+ 'command ' => PHP_BINARY . ' ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
160
+ 'expectedArguments ' => ['exportProcessor ' , '--single-thread ' , '--max-messages=10 ' ],
161
+ ],
162
+ [
163
+ 'specificConsumer ' => 'exportProcessor ' ,
164
+ 'max_messages ' => 5000 ,
165
+ 'command ' => PHP_BINARY . ' ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
166
+ 'expectedArguments ' => ['exportProcessor ' , '--single-thread ' , '--max-messages=100 ' ],
167
+ ],
168
+ ];
169
+ }
170
+
120
171
/**
121
172
* Tests running of specific consumer and his re-running when it is working
122
173
*
0 commit comments