Skip to content

Commit c30098a

Browse files
committed
ACP2E-847: [PHP 8.1] Deprecated Functionality in Framework/Amqp
1 parent b092dd6 commit c30098a

File tree

2 files changed

+82
-20
lines changed

2 files changed

+82
-20
lines changed

lib/internal/Magento/Framework/Amqp/Config.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ class Config
2323
/**
2424
* Queue config key
2525
*/
26-
const QUEUE_CONFIG = 'queue';
26+
public const QUEUE_CONFIG = 'queue';
2727

2828
/**
2929
* Amqp config key
3030
*/
31-
const AMQP_CONFIG = 'amqp';
31+
public const AMQP_CONFIG = 'amqp';
3232

33-
const HOST = 'host';
34-
const PORT = 'port';
35-
const USERNAME = 'user';
36-
const PASSWORD = 'password';
37-
const VIRTUALHOST = 'virtualhost';
38-
const SSL = 'ssl';
39-
const SSL_OPTIONS = 'ssl_options';
33+
public const HOST = 'host';
34+
public const PORT = 'port';
35+
public const USERNAME = 'user';
36+
public const PASSWORD = 'password';
37+
public const VIRTUALHOST = 'virtualhost';
38+
public const SSL = 'ssl';
39+
public const SSL_OPTIONS = 'ssl_options';
4040

4141
/**
4242
* Deployment configuration
@@ -140,7 +140,7 @@ public function getValue($key)
140140
*/
141141
private function createConnection(): AbstractConnection
142142
{
143-
$sslEnabled = trim($this->getValue(self::SSL)) === 'true';
143+
$sslEnabled = $this->getValue(self::SSL) && trim($this->getValue(self::SSL)) === 'true';
144144
$options = new FactoryOptions();
145145
$options->setHost($this->getValue(self::HOST));
146146
$options->setPort($this->getValue(self::PORT));

lib/internal/Magento/Framework/Amqp/Test/Unit/ConfigTest.php

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
namespace Magento\Framework\Amqp\Test\Unit;
99

1010
use Magento\Framework\Amqp\Config;
11+
use Magento\Framework\Amqp\Connection\Factory as ConnectionFactory;
12+
use Magento\Framework\Amqp\Connection\FactoryOptions;
1113
use Magento\Framework\App\DeploymentConfig;
12-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

@@ -21,9 +22,9 @@ class ConfigTest extends TestCase
2122
private $deploymentConfigMock;
2223

2324
/**
24-
* @var ObjectManager
25+
* @var ConnectionFactory
2526
*/
26-
private $objectManager;
27+
private $connectionFactory;
2728

2829
/**
2930
* @var Config
@@ -32,17 +33,12 @@ class ConfigTest extends TestCase
3233

3334
protected function setUp(): void
3435
{
35-
$this->objectManager = new ObjectManager($this);
3636
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
3737
->disableOriginalConstructor()
3838
->setMethods(['getConfigData'])
3939
->getMock();
40-
$this->amqpConfig = $this->objectManager->getObject(
41-
Config::class,
42-
[
43-
'config' => $this->deploymentConfigMock,
44-
]
45-
);
40+
$this->connectionFactory = $this->createMock(ConnectionFactory::class);
41+
$this->amqpConfig = new Config($this->deploymentConfigMock, 'amqp', $this->connectionFactory);
4642
}
4743

4844
public function testGetNullConfig()
@@ -140,4 +136,70 @@ public function testGetCustomConfig()
140136
$this->assertEquals($expectedSsl, $amqpConfig->getValue(Config::SSL));
141137
$this->assertEquals('randomValue', $amqpConfig->getValue('randomKey'));
142138
}
139+
140+
/**
141+
* @param array $config
142+
* @param array $expected
143+
* @return void
144+
* @dataProvider configDataProvider
145+
*/
146+
public function testCreateConnection(array $config, array $expected): void
147+
{
148+
$this->deploymentConfigMock->expects($this->once())
149+
->method('getConfigData')
150+
->with(Config::QUEUE_CONFIG)
151+
->willReturn(
152+
[
153+
Config::AMQP_CONFIG => $config
154+
]
155+
);
156+
$this->connectionFactory->expects($this->once())
157+
->method('create')
158+
->with(
159+
$this->callback(
160+
function (FactoryOptions $factoryOptions) use ($expected) {
161+
$actual = [];
162+
foreach (array_keys($expected) as $method) {
163+
$actual[$method] = $factoryOptions->$method();
164+
}
165+
return $actual === $expected;
166+
}
167+
)
168+
);
169+
$this->amqpConfig->getChannel();
170+
}
171+
172+
/**
173+
* @return array
174+
*/
175+
public function configDataProvider(): array
176+
{
177+
return [
178+
[
179+
[
180+
Config::HOST => 'localhost',
181+
Config::PORT => '5672',
182+
Config::USERNAME => 'user',
183+
Config::PASSWORD => 'pass',
184+
Config::VIRTUALHOST => '/',
185+
],
186+
[
187+
'isSslEnabled' => false
188+
]
189+
],
190+
[
191+
[
192+
Config::HOST => 'localhost',
193+
Config::PORT => '5672',
194+
Config::USERNAME => 'user',
195+
Config::PASSWORD => 'pass',
196+
Config::VIRTUALHOST => '/',
197+
Config::SSL => ' true ',
198+
],
199+
[
200+
'isSslEnabled' => true
201+
]
202+
]
203+
];
204+
}
143205
}

0 commit comments

Comments
 (0)