From d60cbb9ed28d4b307cd2b82721e0f19e501134b4 Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Fri, 21 Feb 2020 17:11:00 +0100 Subject: [PATCH 1/5] Fix for numeric argument conversion --- .../Framework/Amqp/Topology/ArgumentProcessor.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php b/lib/internal/Magento/Framework/Amqp/Topology/ArgumentProcessor.php index caa5db4e7ef5c..2a7b6b939853f 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; } } From 314ec92a7c82b70ac7460c21b2c82085e380d292 Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Sat, 5 Sep 2020 22:23:44 +0200 Subject: [PATCH 2/5] Adding unit test --- .../Unit/Topology/ArgumentProcessorTest.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php 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..ef1098da318ab --- /dev/null +++ b/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php @@ -0,0 +1,73 @@ + 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); + } +} From 69eca0706fdfd74222b8a5aaab5a57bf0c4f0ea7 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 8 Sep 2020 09:40:50 -0500 Subject: [PATCH 3/5] Remove useless doc block --- .../Amqp/Test/Unit/Topology/ArgumentProcessorTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php b/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php index ef1098da318ab..8aaf57bf36543 100644 --- a/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php +++ b/lib/internal/Magento/Framework/Amqp/Test/Unit/Topology/ArgumentProcessorTest.php @@ -14,9 +14,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * Class ArgumentProcessorTest - */ class ArgumentProcessorTest extends TestCase { /** From 1fd701539fef71e05bdcfd7bcf5a09671482d199 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 9 Oct 2020 16:18:07 +0300 Subject: [PATCH 4/5] magento/magento2#26967: Fix for queue numeric argument conversion - integration test update. --- .../Magento/Framework/MessageQueue/TopologyTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php b/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php index c8600e1e38faa..5c85d6ddb7c70 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php @@ -48,7 +48,7 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo $this->assertArrayHasKey($name, $this->declaredExchanges); unset($this->declaredExchanges[$name]['message_stats']); unset($this->declaredExchanges[$name]['user_who_performed_action']); - $this->assertEquals( + $this->assertSame( $expectedConfig, $this->declaredExchanges[$name], 'Invalid exchange configuration: ' . $name @@ -59,7 +59,7 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo unset($value['properties_key']); return $value; }, $bindings); - $this->assertEquals( + $this->assertSame( $bindingConfig, $bindings, 'Invalid exchange bindings configuration: ' . $name @@ -121,7 +121,7 @@ public function exchangeDataProvider() 'arguments' => [ 'argument1' => 'value', 'argument2' => true, - 'argument3' => '150', + 'argument3' => 150, ], ], ] From 8c8b9cf5220db0a8ffdc2ec16f1a092efcbe4fbd Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Mon, 12 Oct 2020 12:59:50 +0200 Subject: [PATCH 5/5] Possible fix for integration test --- .../Framework/MessageQueue/TopologyTest.php | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php b/dev/tests/integration/testsuite/Magento/Framework/MessageQueue/TopologyTest.php index 5c85d6ddb7c70..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,24 +49,28 @@ 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']); - $this->assertSame( + unset( + $this->declaredExchanges[$name]['message_stats'], + $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) { + $bindings = array_map(static function ($value) { unset($value['properties_key']); return $value; }, $bindings); - $this->assertSame( + + $this->assertEquals( $bindingConfig, $bindings, 'Invalid exchange bindings configuration: ' . $name @@ -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' => [