Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExchangeFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
12 class ExchangeFactoryTest extends \PHPUnit\Framework\TestCase
13 {
17  private $connectionTypeResolver;
18 
22  private $amqpExchangeFactory;
23 
27  private $exchangeFactory;
28 
34  protected function setUp()
35  {
36  $this->connectionTypeResolver = $this
37  ->getMockBuilder(\Magento\Framework\MessageQueue\ConnectionTypeResolver::class)
38  ->disableOriginalConstructor()->getMock();
39 
40  $this->amqpExchangeFactory = $this
41  ->getMockBuilder(\Magento\Framework\Amqp\ExchangeFactory::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
46  $this->exchangeFactory = $objectManager->getObject(
47  \Magento\Framework\MessageQueue\Bulk\ExchangeFactory::class,
48  [
49  'connectionTypeResolver' => $this->connectionTypeResolver,
50  'exchangeFactories' => ['amqp' => $this->amqpExchangeFactory],
51  ]
52  );
53  }
54 
60  public function testCreate()
61  {
62  $connectionName = 'amqp';
63  $data = ['key1' => 'value1'];
64  $this->connectionTypeResolver->expects($this->once())
65  ->method('getConnectionType')->with($connectionName)->willReturn($connectionName);
66  $exchange = $this
67  ->getMockBuilder(\Magento\Framework\Amqp\Bulk\Exchange::class)
68  ->disableOriginalConstructor()->getMock();
69  $this->amqpExchangeFactory->expects($this->once())
70  ->method('create')->with($connectionName, $data)->willReturn($exchange);
71  $this->assertEquals($exchange, $this->exchangeFactory->create($connectionName, $data));
72  }
73 
82  {
83  $connectionName = 'db';
84  $data = ['key1' => 'value1'];
85  $this->connectionTypeResolver->expects($this->once())
86  ->method('getConnectionType')->with($connectionName)->willReturn($connectionName);
87  $this->amqpExchangeFactory->expects($this->never())->method('create');
88  $this->exchangeFactory->create($connectionName, $data);
89  }
90 
99  {
100  $connectionName = 'amqp';
101  $data = ['key1' => 'value1'];
102  $this->connectionTypeResolver->expects($this->once())
103  ->method('getConnectionType')->with($connectionName)->willReturn($connectionName);
104  $exchange = $this
105  ->getMockBuilder(\Magento\Framework\Amqp\Exchange::class)
106  ->disableOriginalConstructor()->getMock();
107  $this->amqpExchangeFactory->expects($this->once())
108  ->method('create')->with($connectionName, $data)->willReturn($exchange);
109  $this->exchangeFactory->create($connectionName, $data);
110  }
111 }
$objectManager
Definition: bootstrap.php:17