7 declare(strict_types = 1);
12 use Symfony\Component\Console\Command\Command;
13 use Symfony\Component\Console\Input\InputArgument;
14 use Symfony\Component\Console\Input\InputInterface;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Symfony\Component\Console\Input\InputOption;
28 $this->setName(
'generate:urn-catalog')
29 ->setDescription(
'This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
30 ->addArgument(
'path', InputArgument::REQUIRED,
'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)')
34 InputOption::VALUE_NONE,
35 'forces creation of misc.xml file if not found in the path given.' 49 $miscXmlFilePath = $input->getArgument(
'path') . DIRECTORY_SEPARATOR .
"misc.xml";
50 $miscXmlFile = realpath($miscXmlFilePath);
51 $force = $input->getOption(
'force');
53 if ($miscXmlFile ===
false) {
56 $xml =
"<project version=\"4\"/>";
58 $miscXmlFile = realpath($miscXmlFilePath);
60 $exceptionMessage =
"misc.xml not found in given path '{$miscXmlFilePath}'";
62 ->error($exceptionMessage);
66 $dom = new \DOMDocument(
'1.0');
67 $dom->preserveWhiteSpace =
false;
68 $dom->formatOutput =
true;
73 foreach($dom->getElementsByTagName(
'component') as $child) {
74 if ($child->getAttribute(
'name') ===
'ProjectResources') {
75 $nodeForWork = $child;
78 if ($nodeForWork ===
null) {
79 $project = $dom->getElementsByTagName(
'project')->item(0);
80 $nodeForWork = $dom->createElement(
'component');
81 $nodeForWork->setAttribute(
'name',
'ProjectResources');
87 $resourceNodes = $nodeForWork->getElementsByTagName(
'resource');
88 $resourceCount = $resourceNodes->length;
89 for (
$i = 0;
$i < $resourceCount;
$i++) {
90 $child = $resourceNodes[0];
91 $resources[$child->getAttribute(
'url')] = $child->getAttribute(
'location');
92 $child->parentNode->removeChild($child);
95 $resources = array_merge($resources, $this->generateResourcesArray());
97 foreach ($resources as
$url => $location) {
98 $resourceNode = $dom->createElement(
'resource');
99 $resourceNode->setAttribute(
'url',
$url);
100 $resourceNode->setAttribute(
'location', $location);
101 $nodeForWork->appendChild($resourceNode);
105 $dom->save($miscXmlFile);
106 $output->writeln(
"MFTF URN mapping successfully added to {$miscXmlFile}.");
113 private function generateResourcesArray()
116 'urn:magento:mftf:DataGenerator/etc/dataOperation.xsd' =>
117 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd'),
118 'urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd' =>
119 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd'),
120 'urn:magento:mftf:Page/etc/PageObject.xsd' =>
121 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd'),
122 'urn:magento:mftf:Page/etc/SectionObject.xsd' =>
123 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd'),
124 'urn:magento:mftf:Test/etc/actionGroupSchema.xsd' =>
125 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd'),
126 'urn:magento:mftf:Test/etc/testSchema.xsd' =>
127 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd'),
128 'urn:magento:mftf:Suite/etc/suiteSchema.xsd' =>
129 realpath(FW_BP .
'/src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd')
131 return $resourcesArray;
execute(InputInterface $input, OutputInterface $output)