Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CompositeReaderTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class CompositeReaderTest extends \PHPUnit\Framework\TestCase
13 {
17  private $reader;
18 
22  private $validatorMock;
23 
27  private $readerOneMock;
28 
32  private $readerTwoMock;
33 
37  private $readerThreeMock;
38 
43 
47  protected function setUp()
48  {
49  $this->validatorMock = $this->createMock(ValidatorInterface::class);
50  $this->readerOneMock = $this->createMock(ReaderInterface::class);
51  $this->readerTwoMock = $this->createMock(ReaderInterface::class);
52  $this->readerThreeMock = $this->createMock(ReaderInterface::class);
53  $this->defaultConfigProviderMock =
54  $this->createMock(\Magento\Framework\MessageQueue\DefaultValueProvider::class);
55 
56  $this->reader = new CompositeReader(
57  $this->validatorMock,
58  $this->defaultConfigProviderMock,
59  [
60  'readerOne' => $this->readerOneMock,
61  'readerThree' => $this->readerThreeMock,
62  'readerTwo' => $this->readerTwoMock,
63  ]
64  );
65  }
66 
67  public function testRead()
68  {
69  $this->defaultConfigProviderMock->expects($this->any())->method('getConnection')->willReturn('amqp');
70  $this->defaultConfigProviderMock->expects($this->any())->method('getExchange')->willReturn('magento');
71 
72  $dataOne = include __DIR__ . '/../../_files/queue_publisher/reader_one.php';
73  $dataTwo = include __DIR__ . '/../../_files/queue_publisher/reader_two.php';
74  $expectedValidationData = include __DIR__ . '/../../_files/queue_publisher/data_to_validate.php';
75 
76  $this->readerOneMock->expects($this->once())->method('read')->with(null)->willReturn($dataOne);
77  $this->readerTwoMock->expects($this->once())->method('read')->with(null)->willReturn($dataTwo);
78  $this->readerThreeMock->expects($this->once())->method('read')->with(null)->willReturn([]);
79 
80  $this->validatorMock->expects($this->once())->method('validate')->with($expectedValidationData);
81 
82  $data = $this->reader->read();
83 
84  $expectedData = [
85  //disabling existing connection and adding new
86  'top04' => [
87  'topic' => 'top04',
88  'disabled' => false,
89  'connection' => ['name' => 'db', 'disabled' => false, 'exchange' => 'magento2'],
90  ],
91  //two disabled connections are ignored
92  'top05' => [
93  'topic' => 'top05',
94  'disabled' => false,
95  'connection' => ['name' => 'amqp', 'exchange' => 'exch01', 'disabled' => false],
96  ],
97  //added default connection if not declared
98  'top06' => [
99  'topic' => 'top06',
100  'disabled' => false,
101  'connection' => ['name' => 'amqp', 'exchange' => 'magento', 'disabled' => false],
102  ],
103  //added default connection if all declared connections are disabled
104  'top07' => [
105  'topic' => 'top07',
106  'disabled' => false,
107  'connection' => ['name' => 'amqp', 'exchange' => 'magento', 'disabled' => false],
108  ],
109  ];
110 
111  $this->assertEquals($expectedData, $data);
112  }
113 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60