Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueueTestCaseAbstract.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class QueueTestCaseAbstract extends \PHPUnit\Framework\TestCase
19 {
23  protected $consumers = [];
24 
28  protected $objectManager;
29 
33  protected $publisher;
34 
38  protected $logFilePath;
39 
43  protected $maxMessages = null;
44 
48  private $publisherConsumerController;
49 
50  protected function setUp()
51  {
52  $this->objectManager = Bootstrap::getObjectManager();
53  $this->logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt";
54  $this->publisherConsumerController = $this->objectManager->create(PublisherConsumerController::class, [
55  'consumers' => $this->consumers,
56  'logFilePath' => $this->logFilePath,
57  'maxMessages' => $this->maxMessages,
58  'appInitParams' => \Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppInitParams()
59  ]);
60 
61  try {
62  $this->publisherConsumerController->initialize();
64  $this->markTestSkipped($e->getMessage());
65  } catch (PreconditionFailedException $e) {
66  $this->fail(
67  $e->getMessage()
68  );
69  }
70  $this->publisher = $this->publisherConsumerController->getPublisher();
71  }
72 
73  protected function tearDown()
74  {
75  $this->publisherConsumerController->stopConsumers();
76  }
77 
84  protected function waitForAsynchronousResult($expectedLinesCount, $logFilePath)
85  {
86  try {
87  //$expectedLinesCount, $logFilePath
88  $this->publisherConsumerController->waitForAsynchronousResult([$this, 'checkLogsExists'], [
89  $expectedLinesCount, $logFilePath
90  ]);
91  } catch (PreconditionFailedException $e) {
92  $this->fail($e->getMessage());
93  }
94  }
95 
96  public function checkLogsExists($expectedLinesCount)
97  {
98  $actualCount = file_exists($this->logFilePath) ? count(file($this->logFilePath)) : 0;
99  return $expectedLinesCount === $actualCount;
100  }
101 
105  public static function tearDownAfterClass()
106  {
107  if (version_compare(phpversion(), '7') == -1) {
108  $closeConnection = new \ReflectionMethod(\Magento\Amqp\Model\Config::class, 'closeConnection');
109  $closeConnection->setAccessible(true);
110 
111  $config = Bootstrap::getObjectManager()->get(\Magento\Amqp\Model\Config::class);
112  $closeConnection->invoke($config);
113  }
114  }
115 }
$config
Definition: fraud_order.php:17