Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
XmlConverterCommandTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Symfony\Component\Console\Tester\CommandTester;
14 
15 class XmlConverterCommandTest extends \PHPUnit\Framework\TestCase
16 {
20  private $formatter;
21 
25  private $command;
26 
30  private $domFactory;
31 
35  private $xsltProcessorFactory;
36 
37  protected function setUp()
38  {
39  if (!function_exists('libxml_set_external_entity_loader')) {
40  $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
41  }
42  $this->formatter = $this->createMock(\Magento\Developer\Model\Tools\Formatter::class);
43  $this->domFactory = $this->createMock(\Magento\Framework\DomDocument\DomDocumentFactory::class);
44  $this->xsltProcessorFactory = $this->createMock(\Magento\Framework\XsltProcessor\XsltProcessorFactory::class);
45 
46  $this->command = new XmlConverterCommand($this->formatter, $this->domFactory, $this->xsltProcessorFactory);
47  }
48 
49  public function testExecute()
50  {
51  $domXml = $this->createMock(\DOMDocument::class);
52  $domXsl = clone $domXml;
53  $domXml->expects($this->once())->method('load')->with('file.xml');
54  $domXsl->expects($this->once())->method('load')->with('file.xsl');
55 
56  $this->domFactory->expects($this->at(0))->method('create')->willReturn($domXml);
57  $this->domFactory->expects($this->at(1))->method('create')->willReturn($domXsl);
58 
59  $xsltProcessor = $this->createMock(\XSLTProcessor::class);
60  $xsltProcessor->expects($this->once())->method('transformToXml')->with($domXml)->willReturn('XML');
61 
62  $this->xsltProcessorFactory->expects($this->once())->method('create')->willReturn($xsltProcessor);
63 
64  $this->formatter->expects($this->once())->method('format')->with('XML')->willReturn('result');
65 
66  $commandTester = new CommandTester($this->command);
67  $commandTester->execute(
68  [
71  ]
72  );
73  $this->assertContains('result', $commandTester->getDisplay());
74  }
75 
80  public function testWrongParameter()
81  {
82  $commandTester = new CommandTester($this->command);
83  $commandTester->execute([]);
84  }
85 }