Skip to content

Commit 65a1da6

Browse files
author
Ivan Gavryshko
committed
MAGETWO-37765: Unable to run indexer as part of an install
- fixed
1 parent 649b03a commit 65a1da6

File tree

5 files changed

+69
-57
lines changed

5 files changed

+69
-57
lines changed

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Magento\Developer\Model\Tools\Formatter;
15+
use Magento\Framework\DomDocument\Factory;
16+
use Magento\Framework\XSLTProcessor\Factory as XSLTProcessorFactory;
1517

1618
/**
1719
* Class XmlConverterCommand
@@ -40,14 +42,14 @@ class XmlConverterCommand extends Command
4042
private $formatter;
4143

4244
/**
43-
* @var \DOMDocument
45+
* @var Factory
4446
*/
45-
private $domXml;
47+
private $domFactory;
4648

4749
/**
48-
* @var \DOMDocument
50+
* @var XSLTProcessorFactory
4951
*/
50-
private $domXsl;
52+
private $xsltProcessorFactory;
5153

5254
/**
5355
* @var \XSLTProcessor
@@ -58,21 +60,17 @@ class XmlConverterCommand extends Command
5860
* Inject dependencies
5961
*
6062
* @param Formatter $formatter
61-
* @param \DOMDocument $domXml
62-
* @param \DOMDocument $domXsl
63-
* @param \XSLTProcessor $xsltProcessor
64-
* @SuppressWarnings(Magento.TypeDuplication)
63+
* @param Factory $domFactory
64+
* @param xsltProcessorFactory $xsltProcessorFactory
6565
*/
6666
public function __construct(
6767
Formatter $formatter,
68-
\DOMDocument $domXml,
69-
\DOMDocument $domXsl,
70-
\XSLTProcessor $xsltProcessor
68+
Factory $domFactory,
69+
XSLTProcessorFactory $xsltProcessorFactory
7170
) {
7271
$this->formatter = $formatter;
73-
$this->domXml = $domXml;
74-
$this->domXsl = $domXsl;
75-
$this->xsltProcessor = $xsltProcessor;
72+
$this->domFactory = $domFactory;
73+
$this->xsltProcessorFactory = $xsltProcessorFactory;
7674

7775
parent::__construct();
7876
}
@@ -113,16 +111,20 @@ protected function configure()
113111
protected function execute(InputInterface $input, OutputInterface $output)
114112
{
115113
try {
114+
$domXml = $this->domFactory->createDomDocument();
115+
$domXsl = $this->domFactory->createDomDocument();
116+
$xsltProcessor = $this->xsltProcessorFactory->createXSLTProcessor();
117+
116118
$xmlFile = $input->getArgument(self::XML_FILE_ARGUMENT);
117-
$this->domXml->preserveWhiteSpace = true;
118-
$this->domXml->load($xmlFile);
119+
$domXml->preserveWhiteSpace = true;
120+
$domXml->load($xmlFile);
119121

120-
$this->domXsl->preserveWhiteSpace = true;
121-
$this->domXsl->load($input->getArgument(self::PROCESSOR_ARGUMENT));
122+
$domXsl->preserveWhiteSpace = true;
123+
$domXsl->load($input->getArgument(self::PROCESSOR_ARGUMENT));
122124

123-
$this->xsltProcessor->registerPHPFunctions();
124-
$this->xsltProcessor->importStylesheet($this->domXsl);
125-
$transformedDoc = $this->xsltProcessor->transformToXml($this->domXml);
125+
$xsltProcessor->registerPHPFunctions();
126+
$xsltProcessor->importStylesheet($domXsl);
127+
$transformedDoc = $xsltProcessor->transformToXml($domXml);
126128
$result = $this->formatter->format($transformedDoc);
127129

128130
if ($input->getOption(self::OVERWRITE_OPTION)) {

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Developer\Console\Command\XmlConverterCommand;
1010
use Symfony\Component\Console\Tester\CommandTester;
1111
use Magento\Developer\Model\Tools\Formatter;
12+
use Magento\Framework\DomDocument\Factory;
13+
use Magento\Framework\XSLTProcessor\Factory as XSLTProcessorFactory;
14+
1215

1316
class XmlConverterCommandTest extends \PHPUnit_Framework_TestCase
1417
{
@@ -23,35 +26,38 @@ class XmlConverterCommandTest extends \PHPUnit_Framework_TestCase
2326
private $command;
2427

2528
/**
26-
* @var \DOMDocument|\PHPUnit_Framework_MockObject_MockObject
27-
*/
28-
private $domXml;
29-
30-
/**
31-
* @var \DOMDocument|\PHPUnit_Framework_MockObject_MockObject
29+
* @var Factory|\PHPUnit_Framework_MockObject_MockObject
3230
*/
33-
private $domXsl;
31+
private $domFactory;
3432

3533
/**
36-
* @var \XSLTProcessor|\PHPUnit_Framework_MockObject_MockObject
34+
* @var XSLTProcessorFactory|\PHPUnit_Framework_MockObject_MockObject
3735
*/
38-
private $xsltProcessor;
36+
private $xsltProcessorFactory;
3937

4038
public function setUp()
4139
{
4240
$this->formatter = $this->getMock('Magento\Developer\Model\Tools\Formatter', [], [], '', false);
43-
$this->domXml = $this->getMock('DOMDocument', [], [], '', false);
44-
$this->domXsl = $this->getMock('DOMDocument', [], [], '', false);
45-
$this->xsltProcessor = $this->getMock('XSLTProcessor', [], [], '', false);
46-
$this->command = new XmlConverterCommand($this->formatter, $this->domXml, $this->domXsl, $this->xsltProcessor);
41+
$this->domFactory = $this->getMock('Magento\Framework\DomDocument\Factory', [], [], '', false);
42+
$this->xsltProcessorFactory = $this->getMock('Magento\Framework\XSLTProcessor\Factory', [], [], '', false);
43+
44+
$this->command = new XmlConverterCommand($this->formatter, $this->domFactory, $this->xsltProcessorFactory);
4745
}
4846

4947
public function testExecute()
5048
{
51-
$this->domXml->expects($this->once())->method('load')->with('file.xml');
52-
$this->domXsl->expects($this->once())->method('load')->with('file.xsl');
49+
$domXml = $this->getMock('DOMDocument', [], [], '', false);
50+
$domXsl = clone $domXml;
51+
$domXml->expects($this->once())->method('load')->with('file.xml');
52+
$domXsl->expects($this->once())->method('load')->with('file.xsl');
53+
54+
$this->domFactory->expects($this->at(0))->method('createDomDocument')->willReturn($domXml);
55+
$this->domFactory->expects($this->at(1))->method('createDomDocument')->willReturn($domXsl);
56+
57+
$xsltProcessor = $this->getMock('XSLTProcessor', [], [], '', false);
58+
$xsltProcessor->expects($this->once())->method('transformToXml')->with($domXml)->willReturn('XML');
5359

54-
$this->xsltProcessor->expects($this->once())->method('transformToXml')->with($this->domXml)->willReturn('XML');
60+
$this->xsltProcessorFactory->expects($this->once())->method('createXSLTProcessor')->willReturn($xsltProcessor);
5561

5662
$this->formatter->expects($this->once())->method('format')->with('XML')->willReturn('result');
5763

app/code/Magento/Developer/etc/di.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,4 @@
3232
</argument>
3333
</arguments>
3434
</type>
35-
<type name="Magento\Developer\Console\Command\XmlConverterCommand">
36-
<arguments>
37-
<argument name="domXml" xsi:type="object" shared="false">DOMDocument</argument>
38-
<argument name="domXsl" xsi:type="object" shared="false">DOMDocument</argument>
39-
</arguments>
40-
</type>
4135
</config>

lib/internal/Magento/Framework/DomDocument/Factory.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,13 @@
1010
*/
1111
class Factory
1212
{
13-
/**
14-
* @var \Magento\Framework\ObjectManagerInterface
15-
*/
16-
protected $_objectManager;
17-
18-
/**
19-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
20-
*/
21-
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
22-
{
23-
$this->_objectManager = $objectManager;
24-
}
25-
2613
/**
2714
* Create empty DOM document instance.
2815
*
2916
* @return \DOMDocument
3017
*/
3118
public function createDomDocument()
3219
{
33-
return $this->_objectManager->create('DOMDocument', []);
20+
return new \DOMDocument();
3421
}
3522
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\XSLTProcessor;
7+
8+
/**
9+
* XSLTProcessor document factory
10+
*/
11+
class Factory
12+
{
13+
/**
14+
* Create empty XSLTProcessor instance.
15+
*
16+
* @return \XSLTProcessor
17+
*/
18+
public function createXSLTProcessor()
19+
{
20+
return new \XSLTProcessor();
21+
}
22+
23+
}

0 commit comments

Comments
 (0)