objectManager = Bootstrap::getObjectManager(); $this->logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt"; $this->publisherConsumerController = $this->objectManager->create(PublisherConsumerController::class, [ 'consumers' => $this->consumers, 'logFilePath' => $this->logFilePath, 'maxMessages' => $this->maxMessages, 'appInitParams' => \Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppInitParams() ]); try { $this->publisherConsumerController->initialize(); } catch (EnvironmentPreconditionException $e) { $this->markTestSkipped($e->getMessage()); } catch (PreconditionFailedException $e) { $this->fail( $e->getMessage() ); } $this->publisher = $this->publisherConsumerController->getPublisher(); } protected function tearDown() { $this->publisherConsumerController->stopConsumers(); } /** * Wait for asynchronous handlers to log data to file. * * @param int $expectedLinesCount * @param string $logFilePath */ protected function waitForAsynchronousResult($expectedLinesCount, $logFilePath) { try { //$expectedLinesCount, $logFilePath $this->publisherConsumerController->waitForAsynchronousResult([$this, 'checkLogsExists'], [ $expectedLinesCount, $logFilePath ]); } catch (PreconditionFailedException $e) { $this->fail($e->getMessage()); } } public function checkLogsExists($expectedLinesCount) { $actualCount = file_exists($this->logFilePath) ? count(file($this->logFilePath)) : 0; return $expectedLinesCount === $actualCount; } /** * Workaround for https://bugs.php.net/bug.php?id=72286 */ public static function tearDownAfterClass() { if (version_compare(phpversion(), '7') == -1) { $closeConnection = new \ReflectionMethod(\Magento\Amqp\Model\Config::class, 'closeConnection'); $closeConnection->setAccessible(true); $config = Bootstrap::getObjectManager()->get(\Magento\Amqp\Model\Config::class); $closeConnection->invoke($config); } } }