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 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2018 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -78,7 +78,7 @@ public function __construct(
7878 */
7979 public function execute ($ userFunctions )
8080 {
81- if ($ this ->threadsCount > 1 && $ this -> isCanBeParalleled () && ! $ this -> isSetupMode () && PHP_SAPI == ' cli ' ) {
81+ if ($ this ->isMultiThreadsExecute () ) {
8282 $ this ->multiThreadsExecute ($ userFunctions );
8383 } else {
8484 $ this ->simpleThreadExecute ($ userFunctions );
@@ -196,4 +196,14 @@ private function executeParentProcess(int &$threadNumber)
196196 $ threadNumber --;
197197 }
198198 }
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+ }
199209}
Original file line number Diff line number Diff line change 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2020 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -206,4 +206,37 @@ function () {
206206 ],
207207 ];
208208 }
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+ }
209242}
You can’t perform that action at this time.
0 commit comments