Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TopicConverterTest.php
Go to the documentation of this file.
1 <?php
7 
11 class TopicConverterTest extends \PHPUnit\Framework\TestCase
12 {
16  private $converter;
17 
21  protected $methodMapMock;
22 
26  protected $validatorMock;
27 
32 
36  protected function setUp()
37  {
38  $this->methodMapMock = $this->createMock(\Magento\Framework\Reflection\MethodsMap::class);
39  $this->validatorMock = $this->createMock(\Magento\Framework\MessageQueue\Config\Validator::class);
40  $this->communicationConfigMock = $this->createMock(\Magento\Framework\Communication\ConfigInterface::class);
41  $wildcardPatternMap = include(__DIR__ . '/../../../../_files/wildcard_pattern_map.php');
42  $topicsMap = include(__DIR__ . '/../../../../_files/topic_definitions_map.php');
43  $this->validatorMock->expects($this->any())
44  ->method('buildWildcardPattern')
45  ->willReturnMap($wildcardPatternMap);
46 
47  $topicsDefinitions = [
48  'user.created.remote' => [],
49  'product.created.local' => [],
50  ];
51  $this->communicationConfigMock->expects($this->once())->method('getTopics')->willReturn($topicsDefinitions);
52 
53  $this->communicationConfigMock->expects($this->any())->method('getTopic')->willReturnMap($topicsMap);
54 
55  $this->converter = new \Magento\Framework\MessageQueue\Config\Reader\Xml\Converter\TopicConfig(
56  $this->methodMapMock,
57  $this->validatorMock,
58  $this->communicationConfigMock
59  );
60  }
61 
65  public function testConvert()
66  {
67  $xmlFile = __DIR__ . '/../../../../_files/topic_config.xml';
68  $expectedData = include(__DIR__ . '/../../../../_files/expected_topic_config.php');
69  $dom = new \DOMDocument();
70  $dom->load($xmlFile);
71  $result = $this->converter->convert($dom);
72  $this->assertEquals($expectedData, $result);
73  }
74 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60