Skip to content

Commit d3d7645

Browse files
author
Eugene Tulika
committed
MAGETWO-44440: Register URN resolver to resolve internal dependencies
- Fixed CR comments
1 parent fede586 commit d3d7645

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@
1212
use Symfony\Component\Console\Input\InputOption;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Output\OutputInterface;
15-
use Magento\Framework\App\Utility\Files;
16-
use Magento\Framework\Config\Dom\UrnResolver;
17-
use Magento\Developer\Model\XmlCatalog\Format\FormatInterface;
18-
use Magento\Framework\Filesystem;
19-
use Magento\Framework\Filesystem\Directory\ReadInterface;
2015
use Magento\Framework\App\Filesystem\DirectoryList;
21-
use Magento\Framework\Filesystem\Directory\ReadFactory;
2216

2317
/**
2418
* Class XmlCatalogGenerateCommand Generates dictionary of URNs for the IDE
25-
* @SuppressWarnings("PMD.CouplingBetweenObjects")
2619
*/
2720
class XmlCatalogGenerateCommand extends Command
2821
{
@@ -37,50 +30,42 @@ class XmlCatalogGenerateCommand extends Command
3730
const IDE_FILE_PATH_ARGUMENT = 'path';
3831

3932
/**
40-
* @var Files
33+
* @var \Magento\Framework\App\Utility\Files
4134
*/
4235
private $filesUtility;
4336

4437
/**
45-
* @var UrnResolver
38+
* @var \Magento\Framework\Config\Dom\UrnResolver
4639
*/
4740
private $urnResolver;
4841

4942
/**
50-
* @var ReadInterface
51-
*/
52-
private $currentDirRead;
53-
54-
/**
55-
* @var ReadInterface
43+
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
5644
*/
5745
private $rootDirRead;
5846

5947
/**
6048
* Supported formats
6149
*
62-
* @var FormatInterface[]
50+
* @var \Magento\Developer\Model\XmlCatalog\Format\FormatInterface[]
6351
*/
6452
private $formats;
6553

6654
/**
67-
* @param Files $filesUtility
68-
* @param UrnResolver $urnResolver
69-
* @param Filesystem $filesystemFactory
70-
* @param ReadFactory $readFactory
71-
* @param FormatInterface[] $formats
55+
* @param \Magento\Framework\App\Utility\Files $filesUtility
56+
* @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
57+
* @param \Magento\Framework\Filesystem $filesystemFactory
58+
* @param \Magento\Developer\Model\XmlCatalog\Format\FormatInterface[] $formats
7259
*/
7360
public function __construct(
74-
Files $filesUtility,
75-
UrnResolver $urnResolver,
76-
Filesystem $filesystemFactory,
77-
ReadFactory $readFactory,
61+
\Magento\Framework\App\Utility\Files $filesUtility,
62+
\Magento\Framework\Config\Dom\UrnResolver $urnResolver,
63+
\Magento\Framework\Filesystem $filesystemFactory,
7864
array $formats = []
7965
) {
8066
$this->filesUtility = $filesUtility;
8167
$this->urnResolver = $urnResolver;
8268
$this->formats = $formats;
83-
$this->currentDirRead = $readFactory->create(getcwd());
8469
$this->rootDirRead = $filesystemFactory->getDirectoryRead(DirectoryList::ROOT);
8570
parent::__construct();
8671
}
@@ -156,11 +141,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
156141
{
157142
$ideName = $input->getOption(self::IDE_OPTION);
158143
$ideFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT);
159-
$absolutePath = $this->currentDirRead->getAbsolutePath($ideFilePath);
160144

161145
$urnDictionary = $this->getUrnDictionary($output);
162146
if ($formatter = $this->getFormatters($ideName)) {
163-
$formatter->generateCatalog($urnDictionary, $absolutePath);
147+
$formatter->generateCatalog($urnDictionary, $ideFilePath);
164148
} else {
165149
throw new InputException(__("Format for IDE '%1' is not supported", $ideName));
166150
}
@@ -170,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
170154
* Get formatter based on format
171155
*
172156
* @param string $format
173-
* @return FormatInterface|false
157+
* @return \Magento\Developer\Model\XmlCatalog\Format\FormatInterface|false
174158
*/
175159
private function getFormatters($format)
176160
{

app/code/Magento/Developer/Model/XmlCatalog/Format/PhpStorm.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Developer\Model\XmlCatalog\Format;
88

9+
use Magento\Framework\Exception\FileSystemException;
910
use Magento\Framework\Filesystem\Directory\ReadFactory;
1011
use Magento\Framework\Filesystem\Directory\ReadInterface;
1112
use Magento\Framework\Filesystem\Directory\WriteFactory;
@@ -26,37 +27,49 @@ class PhpStorm implements FormatInterface
2627
*/
2728
private $currentDirWrite;
2829

30+
/**
31+
* @var \Magento\Framework\Filesystem\File\WriteFactory
32+
*/
33+
private $fileWriteFactory;
34+
2935
/**
3036
* @param ReadFactory $readFactory
31-
* @param WriteFactory $writeFactory
37+
* @param \Magento\Framework\Filesystem\File\WriteFactory $fileWriteFactory
3238
*/
3339
public function __construct(
3440
ReadFactory $readFactory,
35-
WriteFactory $writeFactory
41+
\Magento\Framework\Filesystem\File\WriteFactory $fileWriteFactory
3642
) {
3743
$this->currentDirRead = $readFactory->create(getcwd());
38-
$this->currentDirWrite = $writeFactory->create(getcwd());
44+
$this->fileWriteFactory = $fileWriteFactory;
3945
}
4046

4147
/**
4248
* Generate Catalog of URNs for the PhpStorm 9
4349
*
4450
* @param string[] $dictionary
45-
* @param string $configFile absolute path to the PhpStorm misc.xml
51+
* @param string $configFilePath relative path to the PhpStorm misc.xml
4652
* @return void
4753
*/
48-
public function generateCatalog(array $dictionary, $configFile)
54+
public function generateCatalog(array $dictionary, $configFilePath)
4955
{
5056
$componentNode = null;
5157
$projectNode = null;
52-
$configFile = $this->currentDirRead->getRelativePath($configFile);
53-
if ($this->currentDirRead->isExist($configFile) && $this->currentDirRead->isFile($configFile)) {
58+
59+
try {
60+
$file = $this->fileWriteFactory->create(
61+
$configFilePath,
62+
\Magento\Framework\Filesystem\DriverPool::FILE,
63+
'r'
64+
);
5465
$dom = new \DOMDocument();
55-
$dom->load($configFile);
66+
$dom->loadXML($file->readAll());
5667
$xpath = new \DOMXPath($dom);
5768
$nodeList = $xpath->query('/project');
5869
$projectNode = $nodeList->item(0);
59-
} else {
70+
$file->close();
71+
} catch (FileSystemException $f){
72+
//create file if does not exists
6073
$dom = new \DOMDocument();
6174
$projectNode = $dom->createElement('project');
6275

@@ -87,6 +100,12 @@ public function generateCatalog(array $dictionary, $configFile)
87100
$componentNode->appendChild($node);
88101
}
89102
$dom->formatOutput = true;
90-
$this->currentDirWrite->writeFile($configFile, $dom->saveXML());
103+
$file = $this->fileWriteFactory->create(
104+
$configFilePath,
105+
\Magento\Framework\Filesystem\DriverPool::FILE,
106+
'w'
107+
);
108+
$file->write($dom->saveXML());
109+
$file->close();
91110
}
92111
}

app/code/Magento/Developer/Test/Unit/Console/Command/XmlCatalogGenerateCommandTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public function testExecuteBadType()
3232
->method('getRealPath')
3333
->with($this->equalTo('urn:magento:framework:Module/etc/module.xsd'))
3434
->will($this->returnValue($fixtureXmlFile));
35+
3536
$phpstormFormatMock = $this->getMock('\Magento\Developer\Model\XmlCatalog\Format\PhpStorm', [], [], '', false);
3637
$phpstormFormatMock->expects($this->once())
3738
->method('generateCatalog')
3839
->with(
3940
$this->equalTo(['urn:magento:framework:Module/etc/module.xsd' => $fixtureXmlFile]),
40-
$this->equalTo('test_absolute_path')
41+
$this->equalTo('test')
4142
)->will($this->returnValue(null));
4243

4344
$formats = ['phpstorm' => $phpstormFormatMock];
@@ -58,21 +59,10 @@ public function testExecuteBadType()
5859
->method('getDirectoryRead')
5960
->will($this->returnValue($readDirMock));
6061

61-
$currDirMock = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false);
62-
$currDirMock->expects($this->once())
63-
->method('getAbsolutePath')
64-
->with($this->equalTo('test'))
65-
->will($this->returnValue('test_absolute_path'));
66-
$readDirFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadFactory', [], [], '', false);
67-
$readDirFactory->expects($this->once())
68-
->method('create')
69-
->will($this->returnValue($currDirMock));
70-
7162
$this->command = new XmlCatalogGenerateCommand(
7263
$filesMock,
7364
$urnResolverMock,
7465
$filesystem,
75-
$readDirFactory,
7666
$formats
7767
);
7868

0 commit comments

Comments
 (0)