Skip to content

Commit 284ce6e

Browse files
authored
ENGCOM-3753: Integration Test Framework AMQP Helper Flexibility #18978
2 parents 21b358e + c3ff724 commit 284ce6e

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,63 @@
1313
*/
1414
class Amqp
1515
{
16+
const CONFIG_PATH_HOST = 'queue/amqp/host';
17+
const CONFIG_PATH_USER = 'queue/amqp/user';
18+
const CONFIG_PATH_PASSWORD = 'queue/amqp/password';
19+
const DEFAULT_MANAGEMENT_PORT = '15672';
20+
1621
/**
1722
* @var Curl
1823
*/
1924
private $curl;
2025

26+
/**
27+
* @var \Magento\Framework\App\DeploymentConfig
28+
*/
29+
private $deploymentConfig;
30+
2131
/**
2232
* RabbitMQ API host
2333
*
2434
* @var string
2535
*/
26-
private $host = 'http://localhost:15672/api/';
36+
private $host;
2737

2838
/**
2939
* Initialize dependencies.
40+
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
3041
*/
31-
public function __construct()
32-
{
42+
public function __construct(
43+
\Magento\Framework\App\DeploymentConfig $deploymentConfig = null
44+
) {
45+
$this->deploymentConfig = $deploymentConfig ?? \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
46+
->get(\Magento\Framework\App\DeploymentConfig::class);
3347
$this->curl = new Curl();
34-
$this->curl->setCredentials('guest', 'guest');
48+
$this->curl->setCredentials(
49+
$this->deploymentConfig->get(self::CONFIG_PATH_USER),
50+
$this->deploymentConfig->get(self::CONFIG_PATH_PASSWORD)
51+
);
3552
$this->curl->addHeader('content-type', 'application/json');
53+
$this->host = sprintf(
54+
'http://%s:%s/api/',
55+
$this->deploymentConfig->get(self::CONFIG_PATH_HOST),
56+
defined('RABBITMQ_MANAGEMENT_PORT') ? RABBITMQ_MANAGEMENT_PORT : self::DEFAULT_MANAGEMENT_PORT
57+
);
58+
}
59+
60+
/**
61+
* Check that the RabbitMQ instance has the management plugin installed and the api
62+
* is available.
63+
*
64+
* @return bool
65+
*/
66+
public function isAvailable(): bool
67+
{
68+
$this->curl->get($this->host . 'overview');
69+
$data = $this->curl->getBody();
70+
$data = json_decode($data, true);
71+
72+
return isset($data['management_version']);
3673
}
3774

3875
/**

dev/tests/integration/framework/Magento/TestFramework/MessageQueue/PublisherConsumerController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public function initialize()
8080
"This test relies on *nix shell and should be skipped in Windows environment."
8181
);
8282
}
83+
84+
if (!$this->amqpHelper->isAvailable()) {
85+
throw new PreconditionFailedException(
86+
'This test relies on RabbitMQ Management Plugin.'
87+
);
88+
}
89+
8390
$connections = $this->amqpHelper->getConnections();
8491
foreach (array_keys($connections) as $connectionName) {
8592
$this->amqpHelper->deleteConnection($connectionName);

dev/tests/integration/phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
<!-- Connection parameters for MongoDB library tests -->
7373
<!--<const name="MONGODB_CONNECTION_STRING" value="mongodb://localhost:27017"/>-->
7474
<!--<const name="MONGODB_DATABASE_NAME" value="magento_integration_tests"/>-->
75+
<!-- Connection parameters for RabbitMQ tests -->
76+
<!--<const name="RABBITMQ_MANAGEMENT_PORT" value="15672"/>-->
7577
</php>
7678
<!-- Test listeners -->
7779
<listeners>

dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Framework\MessageQueue;
77

8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\TestFramework\MessageQueue\PreconditionFailedException;
10+
811
/**
912
* @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfiguration
1013
* @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfigOverride
@@ -25,7 +28,12 @@ class TopologyTest extends \PHPUnit\Framework\TestCase
2528

2629
protected function setUp()
2730
{
28-
$this->helper = new \Magento\TestFramework\Helper\Amqp();
31+
$this->helper = Bootstrap::getObjectManager()->create(\Magento\TestFramework\Helper\Amqp::class);
32+
33+
if (!$this->helper->isAvailable()) {
34+
$this->fail('This test relies on RabbitMQ Management Plugin.');
35+
}
36+
2937
$this->declaredExchanges = $this->helper->getExchanges();
3038
}
3139

@@ -39,6 +47,7 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo
3947
$name = $expectedConfig['name'];
4048
$this->assertArrayHasKey($name, $this->declaredExchanges);
4149
unset($this->declaredExchanges[$name]['message_stats']);
50+
unset($this->declaredExchanges[$name]['user_who_performed_action']);
4251
$this->assertEquals(
4352
$expectedConfig,
4453
$this->declaredExchanges[$name],

0 commit comments

Comments
 (0)