File tree Expand file tree Collapse file tree 2 files changed +48
-5
lines changed Expand file tree Collapse file tree 2 files changed +48
-5
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2018 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -78,7 +78,7 @@ public function __construct(
78
78
*/
79
79
public function execute ($ userFunctions )
80
80
{
81
- if ($ this ->threadsCount > 1 && $ this -> isCanBeParalleled () && ! $ this -> isSetupMode () && PHP_SAPI == ' cli ' ) {
81
+ if ($ this ->isMultiThreadsExecute () ) {
82
82
$ this ->multiThreadsExecute ($ userFunctions );
83
83
} else {
84
84
$ this ->simpleThreadExecute ($ userFunctions );
@@ -196,4 +196,14 @@ private function executeParentProcess(int &$threadNumber)
196
196
$ threadNumber --;
197
197
}
198
198
}
199
+
200
+ /**
201
+ * Check if the current process is multithreaded
202
+ *
203
+ * @return bool
204
+ */
205
+ public function isMultiThreadsExecute (): bool
206
+ {
207
+ return $ this ->threadsCount > 1 && $ this ->isCanBeParalleled () && !$ this ->isSetupMode () && PHP_SAPI == 'cli ' ;
208
+ }
199
209
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2020 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -206,4 +206,37 @@ function () {
206
206
],
207
207
];
208
208
}
209
+
210
+ /**
211
+ * @dataProvider testIsMultiThreadsExecuteDataProvider
212
+ * @param $threadsCount
213
+ * @param $expectedResult
214
+ * @return void
215
+ * @throws \PHPUnit\Framework\MockObject\Exception
216
+ */
217
+ public function testIsMultiThreadsExecute ($ threadsCount , $ expectedResult ): void
218
+ {
219
+ $ connectionMock = $ this ->createMock (ResourceConnection::class);
220
+ $ registryMock = $ this ->createMock (Registry::class);
221
+ $ loggerMock = $ this ->createMock (LoggerInterface::class);
222
+ $ amqpConfigPoolMock = $ this ->createMock (AmqpConfigPool::class);
223
+ $ processManager = new ProcessManager (
224
+ $ connectionMock ,
225
+ $ registryMock ,
226
+ $ threadsCount ,
227
+ $ loggerMock ,
228
+ $ amqpConfigPoolMock
229
+ );
230
+ $ this ->assertEquals ($ expectedResult , $ processManager ->isMultiThreadsExecute ());
231
+ }
232
+
233
+ public static function testIsMultiThreadsExecuteDataProvider (): array
234
+ {
235
+ return [
236
+ 'threadsCount is null ' => [null , false ],
237
+ 'threadsCount is 0 ' => [0 , false ],
238
+ 'threadsCount is 1 ' => [1 , false ],
239
+ 'threadsCount is 2 ' => [2 , true ],
240
+ ];
241
+ }
209
242
}
You can’t perform that action at this time.
0 commit comments