_model = new \Magento\Framework\Indexer\Config\Converter(); } public function testConvert() { $data = include __DIR__ . '/../_files/indexer_config.php'; $dom = new \DOMDocument(); $dom->loadXML($data['inputXML']); $this->assertEquals($data['expected'], $this->_model->convert($dom)); } /** * @param string $xml * @param array $indexersSequence * @dataProvider convertWithDependenciesDataProvider */ public function testConvertWithDependencies(string $xml, array $indexersSequence) { $dom = new \DOMDocument(); $dom->loadXML($xml); $this->assertEquals($indexersSequence, array_keys($this->_model->convert($dom))); } /** * @return array */ public function convertWithDependenciesDataProvider() { return [ [ 'xml' => << XML , 'indexersSequence' => [ 'indexer_3', 'indexer_2', 'indexer_6', 'indexer_1', 'indexer_5', 'indexer_4', ], ] ]; } /** * @param string $inputXml * @param string $exceptionMessage * @dataProvider convertWithCircularDependenciesDataProvider */ public function testConvertWithCircularDependencies($inputXml, $exceptionMessage) { $dom = new \DOMDocument(); $dom->loadXML($inputXml); $this->expectException(ConfigurationMismatchException::class); $this->expectExceptionMessage($exceptionMessage); $this->_model->convert($dom); } /** * @return array */ public function convertWithCircularDependenciesDataProvider() { return [ 'Circular dependency on the first level' => [ 'inputXML' => '' . '' . '' . '', 'exceptionMessage' => "Circular dependency references from 'indexer_2' to 'indexer_1'.", ], 'Circular dependency a deeper than the first level' => [ 'inputXML' => '' . '' . '' . '' . '' . '', 'exceptionMessage' => "Circular dependency references from 'indexer_4' to 'indexer_1'.", ], ]; } /** * @param string $inputXml * @param string $exceptionMessage * @dataProvider convertWithDependencyOnNotExistingIndexerDataProvider */ public function testConvertWithDependencyOnNotExistingIndexer($inputXml, $exceptionMessage) { $dom = new \DOMDocument(); $dom->loadXML($inputXml); $this->expectException(ConfigurationMismatchException::class); $this->expectExceptionMessage($exceptionMessage); $this->_model->convert($dom); } /** * @return array */ public function convertWithDependencyOnNotExistingIndexerDataProvider() { return [ [ 'inputXML' => '' . '' . '' . '', 'exceptionMessage' => "Dependency declaration 'indexer_3' in 'indexer_1' to the non-existing indexer.", ], ]; } }