ConverterTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Event\Test\Unit\Config;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. use Magento\Framework\Event\Config\Converter;
  9. class ConverterTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var Converter
  13. */
  14. protected $model;
  15. /**
  16. * @var string
  17. */
  18. protected $filePath;
  19. /**
  20. * @var \DOMDocument
  21. */
  22. protected $source;
  23. /**
  24. * @var ObjectManagerHelper
  25. */
  26. protected $objectManagerHelper;
  27. protected function setUp()
  28. {
  29. $this->objectManagerHelper = new ObjectManagerHelper($this);
  30. $this->filePath = __DIR__ . '/_files/';
  31. $this->source = new \DOMDocument();
  32. $this->model = $this->objectManagerHelper->getObject(Converter::class);
  33. }
  34. public function testConvert()
  35. {
  36. $this->source->loadXML(file_get_contents($this->filePath . 'event_config.xml'));
  37. $convertedFile = include $this->filePath . 'event_config.php';
  38. $this->assertEquals($convertedFile, $this->model->convert($this->source));
  39. }
  40. /**
  41. * @expectedException \InvalidArgumentException
  42. * @expectedExceptionMessage Attribute name is missed
  43. */
  44. public function testConvertThrowsExceptionWhenDomIsInvalid()
  45. {
  46. $this->source->loadXML(file_get_contents($this->filePath . 'event_invalid_config.xml'));
  47. $this->model->convert($this->source);
  48. }
  49. }