markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); } $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); $this->schemaFile = $urnResolver->getRealPath('urn:magento:framework-message-queue:etc/consumer.xsd'); $this->schemaQueueFile = $urnResolver->getRealPath('urn:magento:framework-message-queue:etc/queue.xsd'); } /** * @param string $fixtureXml * @param array $expectedErrors * @dataProvider exemplarXmlDataProvider */ public function testExemplarXml($fixtureXml, array $expectedErrors) { $validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class); $validationState->expects($this->atLeastOnce()) ->method('isValidationRequired') ->willReturn(true); $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationState, [], null, null, $messageFormat); $actualErrors = []; $actualResult = $dom->validate($this->schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); } /** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function exemplarXmlDataProvider() { // @codingStandardsIgnoreStart return [ /** Valid configurations */ 'valid' => [ ' ', [], ], 'non unique consumer name' => [ ' ', [ "Element 'consumer': Duplicate key-sequence ['consumer1'] in unique identity-constraint 'consumer-unique-name'." ], ], 'invalid handler format' => [ ' ', [ "Element 'consumer', attribute 'handler': [facet 'pattern'] The value 'handlerClass1::handlerMethodOne' is not accepted by the pattern '[a-zA-Z\\\\]+::[a-zA-Z]+'.", "Element 'consumer', attribute 'handler': 'handlerClass1::handlerMethodOne' is not a valid value of the atomic type 'handlerType'.", "Element 'consumer', attribute 'handler': [facet 'pattern'] The value 'handlerClassTwo::handlerMethod2' is not accepted by the pattern '[a-zA-Z\\\\]+::[a-zA-Z]+'.", "Element 'consumer', attribute 'handler': 'handlerClassTwo::handlerMethod2' is not a valid value of the atomic type 'handlerType'.", ], ], 'invalid maxMessages format' => [ ' ', [ "Element 'consumer', attribute 'maxMessages': 'ABC' is not a valid value of the atomic type 'xs:integer'.", ], ], 'unexpected element' => [ ' ', [ "Element 'unexpected': This element is not expected. Expected is ( consumer ).", ], ], 'unexpected attribute' => [ ' ', [ "Element 'consumer', attribute 'unexpected': The attribute 'unexpected' is not allowed.", ], ], ]; // @codingStandardsIgnoreEnd } /** * @param string $fixtureXml * @param array $expectedErrors * @dataProvider exemplarQueueXmlDataProvider */ public function testExemplarQueueXml($fixtureXml, array $expectedErrors) { $validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class); $validationState->expects($this->atLeastOnce()) ->method('isValidationRequired') ->willReturn(true); $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationState, [], null, null, $messageFormat); $actualErrors = []; $actualResult = $dom->validate($this->schemaQueueFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); } /** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function exemplarQueueXmlDataProvider() { // @codingStandardsIgnoreStart return [ 'valid' => [ ' ', [], ], 'invalid handler format' => [ ' ', [ "Element 'queue', attribute 'handler': [facet 'pattern'] The value 'handlerClass_One1::handlerMethod1' is not accepted by the pattern '[a-zA-Z0-9\\\\]+::[a-zA-Z0-9]+'.", "Element 'queue', attribute 'handler': 'handlerClass_One1::handlerMethod1' is not a valid value of the atomic type 'handlerType'.", "Element 'queue', attribute 'handler': [facet 'pattern'] The value 'handlerClassOne2::handler_Method2' is not accepted by the pattern '[a-zA-Z0-9\\\\]+::[a-zA-Z0-9]+'.", "Element 'queue', attribute 'handler': 'handlerClassOne2::handler_Method2' is not a valid value of the atomic type 'handlerType'.", ], ], 'invalid instance format' => [ ' ', [ "Element 'queue', attribute 'consumerInstance': [facet 'pattern'] The value 'consumer_Class1' is not accepted by the pattern '[a-zA-Z0-9\\\\]+'.", "Element 'queue', attribute 'consumerInstance': 'consumer_Class1' is not a valid value of the atomic type 'instanceType'.", "Element 'queue', attribute 'consumerInstance': [facet 'pattern'] The value 'consumerClass_2' is not accepted by the pattern '[a-zA-Z0-9\\\\]+'.", "Element 'queue', attribute 'consumerInstance': 'consumerClass_2' is not a valid value of the atomic type 'instanceType'.", ], ], 'invalid maxMessages format' => [ ' ', [ "Element 'queue', attribute 'maxMessages': 'ABC' is not a valid value of the atomic type 'xs:integer'.", ], ], 'unexpected element' => [ ' ', [ "Element 'unexpected': This element is not expected. Expected is ( queue ).", ], ], 'unexpected attribute' => [ ' ', [ "Element 'queue', attribute 'unexpected': The attribute 'unexpected' is not allowed.", ], ], ]; // @codingStandardsIgnoreEnd } }