123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\MessageQueue;
- use Magento\TestFramework\Helper\Bootstrap;
- use Magento\TestFramework\MessageQueue\PreconditionFailedException;
- /**
- * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfiguration
- * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfigOverride
- */
- class TopologyTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * List of declared exchanges.
- *
- * @var array
- */
- private $declaredExchanges;
- /**
- * @var \Magento\TestFramework\Helper\Amqp
- */
- private $helper;
- protected function setUp()
- {
- $this->helper = Bootstrap::getObjectManager()->create(\Magento\TestFramework\Helper\Amqp::class);
- if (!$this->helper->isAvailable()) {
- $this->fail('This test relies on RabbitMQ Management Plugin.');
- }
- $this->declaredExchanges = $this->helper->getExchanges();
- }
- /**
- * @dataProvider exchangeDataProvider
- * @param array $expectedConfig
- * @param array $bindingConfig
- */
- public function testTopologyInstallation(array $expectedConfig, array $bindingConfig)
- {
- $name = $expectedConfig['name'];
- $this->assertArrayHasKey($name, $this->declaredExchanges);
- unset($this->declaredExchanges[$name]['message_stats']);
- unset($this->declaredExchanges[$name]['user_who_performed_action']);
- $this->assertEquals(
- $expectedConfig,
- $this->declaredExchanges[$name],
- 'Invalid exchange configuration: ' . $name
- );
- $bindings = $this->helper->getExchangeBindings($name);
- $bindings = array_map(function ($value) {
- unset($value['properties_key']);
- return $value;
- }, $bindings);
- $this->assertEquals(
- $bindingConfig,
- $bindings,
- 'Invalid exchange bindings configuration: ' . $name
- );
- }
- /**
- * @return array
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function exchangeDataProvider()
- {
- return [
- 'magento-topic-based-exchange1' => [
- 'exchangeConfig' => [
- 'name' => 'magento-topic-based-exchange1',
- 'vhost' => '/',
- 'type' => 'topic',
- 'durable' => true,
- 'auto_delete' => false,
- 'internal' => false,
- 'arguments' => [
- 'alternate-exchange' => 'magento-log-exchange'
- ],
- ],
- 'bindingConfig' => [
- [
- 'source' => 'magento-topic-based-exchange1',
- 'vhost' => '/',
- 'destination' => 'topic-queue1',
- 'destination_type' => 'queue',
- 'routing_key' => 'anotherTopic1',
- 'arguments' => [
- 'argument1' => 'value'
- ],
- ],
- ]
- ],
- 'magento-topic-based-exchange2' => [
- 'exchangeConfig' => [
- 'name' => 'magento-topic-based-exchange2',
- 'vhost' => '/',
- 'type' => 'topic',
- 'durable' => true,
- 'auto_delete' => false,
- 'internal' => false,
- 'arguments' => [
- 'alternate-exchange' => 'magento-log-exchange',
- 'arrayValue' => ['10', '20']
- ],
- ],
- 'bindingConfig' => [
- [
- 'source' => 'magento-topic-based-exchange2',
- 'vhost' => '/',
- 'destination' => 'topic-queue2',
- 'destination_type' => 'queue',
- 'routing_key' => 'anotherTopic2',
- 'arguments' => [
- 'argument1' => 'value',
- 'argument2' => true,
- 'argument3' => '150',
- ],
- ],
- ]
- ],
- 'magento-topic-based-exchange3' => [
- 'exchangeConfig' => [
- 'name' => 'magento-topic-based-exchange3',
- 'vhost' => '/',
- 'type' => 'topic',
- 'durable' => false,
- 'auto_delete' => true,
- 'internal' => true,
- 'arguments' => [],
- ],
- 'bindingConfig' => [],
- ],
- 'magento-topic-based-exchange4' => [
- 'exchangeConfig' => [
- 'name' => 'magento-topic-based-exchange4',
- 'vhost' => '/',
- 'type' => 'topic',
- 'durable' => true,
- 'auto_delete' => false,
- 'internal' => false,
- 'arguments' => [],
- ],
- 'bindingConfig' => [
- [
- 'source' => 'magento-topic-based-exchange4',
- 'vhost' => '/',
- 'destination' => 'topic-queue1',
- 'destination_type' => 'queue',
- 'routing_key' => '#',
- 'arguments' => [
- 'test' => 'one'
- ],
- ],
- [
- 'source' => 'magento-topic-based-exchange4',
- 'vhost' => '/',
- 'destination' => 'topic-queue2',
- 'destination_type' => 'queue',
- 'routing_key' => '*.*.*',
- 'arguments' => [],
- ],
- ]
- ],
- ];
- }
- }
|