Skip to content
Snippets Groups Projects
Commit a781bf6f authored by Timon de Groot's avatar Timon de Groot
Browse files

Add backwards compatibility to XmlCatalog PhpStorm changes

parent 0d652139
Branches
No related merge requests found
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
namespace Magento\Developer\Model\XmlCatalog\Format; namespace Magento\Developer\Model\XmlCatalog\Format;
use Magento\Developer\Model\XmlCatalog\Format\PhpStorm\DomDocumentFactory; use Magento\Developer\Model\XmlCatalog\Format\PhpStorm\DomDocumentFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\Directory\ReadFactory; use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\Filesystem\Directory\ReadInterface;
use Magento\Framework\Filesystem\File\WriteFactory as FileWriteFactory; use Magento\Framework\Filesystem\File\WriteFactory;
/** /**
* Class PhpStorm generates URN catalog for PhpStorm 9 * Class PhpStorm generates URN catalog for PhpStorm 9
...@@ -23,7 +24,7 @@ class PhpStorm implements FormatInterface ...@@ -23,7 +24,7 @@ class PhpStorm implements FormatInterface
private $currentDirRead; private $currentDirRead;
/** /**
* @var FileWriteFactory * @var WriteFactory
*/ */
private $fileWriteFactory; private $fileWriteFactory;
...@@ -34,17 +35,17 @@ class PhpStorm implements FormatInterface ...@@ -34,17 +35,17 @@ class PhpStorm implements FormatInterface
/** /**
* @param ReadFactory $readFactory * @param ReadFactory $readFactory
* @param FileWriteFactory $fileWriteFactory * @param WriteFactory $fileWriteFactory
* @param DomDocumentFactory $domDocumentFactory * @param DomDocumentFactory $domDocumentFactory
*/ */
public function __construct( public function __construct(
ReadFactory $readFactory, ReadFactory $readFactory,
FileWriteFactory $fileWriteFactory, WriteFactory $fileWriteFactory,
DomDocumentFactory $domDocumentFactory DomDocumentFactory $domDocumentFactory = null
) { ) {
$this->currentDirRead = $readFactory->create(getcwd()); $this->currentDirRead = $readFactory->create(getcwd());
$this->fileWriteFactory = $fileWriteFactory; $this->fileWriteFactory = $fileWriteFactory;
$this->domDocumentFactory = $domDocumentFactory; $this->domDocumentFactory = $domDocumentFactory ?: ObjectManager::getInstance()->get(DomDocumentFactory::class);
} }
/** /**
......
...@@ -7,14 +7,28 @@ namespace Magento\Developer\Model\XmlCatalog\Format\PhpStorm; ...@@ -7,14 +7,28 @@ namespace Magento\Developer\Model\XmlCatalog\Format\PhpStorm;
use DOMDocument; use DOMDocument;
class DomDocumentFactory extends \Magento\Framework\DomDocument\DomDocumentFactory class DomDocumentFactory
{ {
/**
* @var \Magento\Framework\DomDocument\DomDocumentFactory
*/
private $documentFactory;
/**
* DomDocumentFactory constructor.
* @param \Magento\Framework\DomDocument\DomDocumentFactory $documentFactory
*/
public function __construct(\Magento\Framework\DomDocument\DomDocumentFactory $documentFactory)
{
$this->documentFactory = $documentFactory;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function create($data = null) public function create(string $data = null)
{ {
$dom = parent::create($data); $dom = $this->documentFactory->create($data);
if (empty($data)) { if (empty($data)) {
$this->initializeDocument($dom); $this->initializeDocument($dom);
......
...@@ -34,11 +34,12 @@ class DomDocumentFactory ...@@ -34,11 +34,12 @@ class DomDocumentFactory
* *
* @return DOMDocument * @return DOMDocument
*/ */
public function create($data = null) public function create(string $data = null)
{ {
/** @var DOMDocument $dom */
$dom = $this->objectManager->create(DOMDocument::class); $dom = $this->objectManager->create(DOMDocument::class);
if (!empty($data) && is_string($data)) { if (!empty($data)) {
$dom->loadXML($data); $dom->loadXML($data);
} }
......
...@@ -68,14 +68,14 @@ EOT; ...@@ -68,14 +68,14 @@ EOT;
->with(DOMDocument::class) ->with(DOMDocument::class)
->willReturn($this->domDocumentMock); ->willReturn($this->domDocumentMock);
if (empty($data) || !is_string($data)) { if (!empty($data)) {
$this->domDocumentMock->expects($this->never())
->method('loadXML');
} else {
$this->domDocumentMock->expects($this->once()) $this->domDocumentMock->expects($this->once())
->method('loadXML') ->method('loadXML')
->with($data) ->with($data)
->willReturn(true); ->willReturn(true);
} else {
$this->domDocumentMock->expects($this->never())
->method('loadXML');
} }
$this->domDocumentFactory->create($data); $this->domDocumentFactory->create($data);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment