Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class ConfigTest extends \PHPUnit\Framework\TestCase
13 {
17  private $deploymentConfigMock;
18 
22  private $objectManager;
23 
27  private $amqpConfig;
28 
29  protected function setUp()
30  {
31  $this->objectManager = new ObjectManager($this);
32  $this->deploymentConfigMock = $this->getMockBuilder(\Magento\Framework\App\DeploymentConfig::class)
33  ->disableOriginalConstructor()
34  ->setMethods(['getConfigData'])
35  ->getMock();
36  $this->amqpConfig = $this->objectManager->getObject(
37  \Magento\Framework\Amqp\Config::class,
38  [
39  'config' => $this->deploymentConfigMock,
40  ]
41  );
42  }
43 
48  public function testGetNullConfig()
49  {
50  $this->deploymentConfigMock->expects($this->once())
51  ->method('getConfigData')
52  ->with(Config::QUEUE_CONFIG)
53  ->will($this->returnValue(null));
54 
55  $this->amqpConfig->getValue(Config::HOST);
56  }
57 
62  public function testGetEmptyConfig()
63  {
64  $this->deploymentConfigMock->expects($this->once())
65  ->method('getConfigData')
66  ->with(Config::QUEUE_CONFIG)
67  ->will($this->returnValue([]));
68 
69  $this->amqpConfig->getValue(Config::HOST);
70  }
71 
72  public function testGetStandardConfig()
73  {
74  $expectedHost = 'example.com';
75  $expectedPort = 5672;
76  $expectedUsername = 'guest_username';
77  $expectedPassword = 'guest_password';
78  $expectedVirtualHost = '/';
79  $expectedSsl = false;
80  $expectedSslOptions = ['some' => 'value'];
81 
82  $this->deploymentConfigMock->expects($this->once())
83  ->method('getConfigData')
84  ->with(Config::QUEUE_CONFIG)
85  ->will($this->returnValue(
86  [
88  'host' => $expectedHost,
89  'port' => $expectedPort,
90  'user' => $expectedUsername,
91  'password' => $expectedPassword,
92  'virtualhost' => $expectedVirtualHost,
93  'ssl' => $expectedSsl,
94  'ssl_options' => $expectedSslOptions,
95  'randomKey' => 'randomValue',
96  ]
97  ]
98  ));
99 
100  $this->assertEquals($expectedHost, $this->amqpConfig->getValue(Config::HOST));
101  $this->assertEquals($expectedPort, $this->amqpConfig->getValue(Config::PORT));
102  $this->assertEquals($expectedUsername, $this->amqpConfig->getValue(Config::USERNAME));
103  $this->assertEquals($expectedPassword, $this->amqpConfig->getValue(Config::PASSWORD));
104  $this->assertEquals($expectedVirtualHost, $this->amqpConfig->getValue(Config::VIRTUALHOST));
105  $this->assertEquals($expectedSsl, $this->amqpConfig->getValue(Config::SSL));
106  $this->assertEquals($expectedSslOptions, $this->amqpConfig->getValue(Config::SSL_OPTIONS));
107  $this->assertEquals('randomValue', $this->amqpConfig->getValue('randomKey'));
108  }
109 
110  public function testGetCustomConfig()
111  {
112  $amqpConfig = new \Magento\Framework\Amqp\Config($this->deploymentConfigMock, 'connection-01');
113  $expectedHost = 'example.com';
114  $expectedPort = 5672;
115  $expectedUsername = 'guest_username';
116  $expectedPassword = 'guest_password';
117  $expectedVirtualHost = '/';
118  $expectedSsl = ['some' => 'value'];
119 
120  $this->deploymentConfigMock->expects($this->once())
121  ->method('getConfigData')
122  ->with(Config::QUEUE_CONFIG)
123  ->will($this->returnValue(
124  [
125  'connections' => [
126  'connection-01' => [
127  'host' => $expectedHost,
128  'port' => $expectedPort,
129  'user' => $expectedUsername,
130  'password' => $expectedPassword,
131  'virtualhost' => $expectedVirtualHost,
132  'ssl' => $expectedSsl,
133  'randomKey' => 'randomValue',
134  ]
135  ]
136  ]
137  ));
138 
139  $this->assertEquals($expectedHost, $amqpConfig->getValue(Config::HOST));
140  $this->assertEquals($expectedPort, $amqpConfig->getValue(Config::PORT));
141  $this->assertEquals($expectedUsername, $amqpConfig->getValue(Config::USERNAME));
142  $this->assertEquals($expectedPassword, $amqpConfig->getValue(Config::PASSWORD));
143  $this->assertEquals($expectedVirtualHost, $amqpConfig->getValue(Config::VIRTUALHOST));
144  $this->assertEquals($expectedSsl, $amqpConfig->getValue(Config::SSL));
145  $this->assertEquals('randomValue', $amqpConfig->getValue('randomKey'));
146  }
147 }