diff --git a/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php b/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php index c8600e1e38faa..cbe48c99da020 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php @@ -3,16 +3,20 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\Framework\MessageQueue; +use Magento\TestFramework\Helper\Amqp; use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\MessageQueue\PreconditionFailedException; +use PHPUnit\Framework\TestCase; /** * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfiguration * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfigOverride */ -class TopologyTest extends \PHPUnit\Framework\TestCase +class TopologyTest extends TestCase { /** * List of declared exchanges. @@ -22,13 +26,16 @@ class TopologyTest extends \PHPUnit\Framework\TestCase private $declaredExchanges; /** - * @var \Magento\TestFramework\Helper\Amqp + * @var Amqp */ private $helper; + /** + * @return void + */ protected function setUp(): void { - $this->helper = Bootstrap::getObjectManager()->create(\Magento\TestFramework\Helper\Amqp::class); + $this->helper = Bootstrap::getObjectManager()->create(Amqp::class); if (!$this->helper->isAvailable()) { $this->fail('This test relies on RabbitMQ Management Plugin.'); @@ -42,12 +49,15 @@ protected function setUp(): void * @param array $expectedConfig * @param array $bindingConfig */ - public function testTopologyInstallation(array $expectedConfig, array $bindingConfig) + public function testTopologyInstallation(array $expectedConfig, array $bindingConfig): void { $name = $expectedConfig['name']; $this->assertArrayHasKey($name, $this->declaredExchanges); - unset($this->declaredExchanges[$name]['message_stats']); - unset($this->declaredExchanges[$name]['user_who_performed_action']); + unset( + $this->declaredExchanges[$name]['message_stats'], + $this->declaredExchanges[$name]['user_who_performed_action'] + ); + $this->assertEquals( $expectedConfig, $this->declaredExchanges[$name], @@ -55,10 +65,11 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo ); $bindings = $this->helper->getExchangeBindings($name); - $bindings = array_map(function ($value) { + $bindings = array_map(static function ($value) { unset($value['properties_key']); return $value; }, $bindings); + $this->assertEquals( $bindingConfig, $bindings, @@ -70,7 +81,7 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function exchangeDataProvider() + public function exchangeDataProvider(): array { return [ 'magento-topic-based-exchange1' => [ @@ -121,7 +132,7 @@ public function exchangeDataProvider() 'arguments' => [ 'argument1' => 'value', 'argument2' => true, - 'argument3' => '150', + 'argument3' => 150, ], ], ] diff --git a/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php b/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php new file mode 100644 index 0000000000000..8aaf57bf36543 --- /dev/null +++ b/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php @@ -0,0 +1,70 @@ + new class { + } + ]; + + $this->expectException(InvalidArgumentException::class); + $this->argumentProcessor->processArguments($arguments); + } + + /** + * @return void + */ + public function testProcessArgumentsWhenAllArgumentAreCorrect(): void + { + $arguments = [ + 'array_type' => ['some_key' => 'some_value'], + 'numeric_value' => '25', + 'integer_value' => 26, + 'boolean_value' => false, + 'string_value' => 'test' + ]; + + $expected = [ + 'array_type' => ['A', ['some_key' => 'some_value']], + 'numeric_value' => ['I', 25], + 'integer_value' => ['I', 26], + 'boolean_value' => ['t', false], + 'string_value' => ['S', 'test'] + ]; + + $this->assertSame($expected, $this->argumentProcessor->processArguments($arguments)); + } + + /** + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + $this->argumentProcessor = $this->getMockForTrait(ArgumentProcessor::class); + } +} diff --git a/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php b/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php index d5aaf1769eae4..27fc62dbf9821 100644 --- a/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php +++ b/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php @@ -1,10 +1,15 @@ $value) { if (is_array($value)) { $output[$key] = ['A', $value]; - } elseif (is_int($value)) { - $output[$key] = ['I', $value]; + } elseif (is_numeric($value)) { + $output[$key] = ['I', (int) $value]; } elseif (is_bool($value)) { $output[$key] = ['t', $value]; } elseif (is_string($value)) { $output[$key] = ['S', $value]; } else { - throw new \InvalidArgumentException('Unknown argument type ' . gettype($value)); + throw new InvalidArgumentException('Unknown argument type ' . gettype($value)); } } + return $output; } }