CompositeTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Config\Converter;
  7. use Magento\Ui\Config\Converter\Composite;
  8. use Magento\Ui\Config\ConverterInterface;
  9. class CompositeTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var ConverterInterface|\PHPUnit_Framework_MockObject_MockObject
  13. */
  14. private $converter;
  15. public function setUp()
  16. {
  17. $this->converter = $this->getMockBuilder(ConverterInterface::class)->getMockForAbstractClass();
  18. }
  19. public function testConvert()
  20. {
  21. $expectedResult = ['converted config'];
  22. $dom = new \DOMDocument('1.0', 'UTF-8');
  23. $element = $dom->createElement('name');
  24. $dom->appendChild($element);
  25. $composite = new Composite(['key' => $this->converter], 'type');
  26. $this->converter->expects($this->once())
  27. ->method('convert')
  28. ->with($element)
  29. ->willReturn($expectedResult);
  30. $this->assertEquals($expectedResult, $composite->convert($element, ['type' => 'key']));
  31. }
  32. /**
  33. * @return void
  34. * @expectedException \InvalidArgumentException
  35. * @expectedExceptionMessage Argument converter named 'missedKey' has not been defined.
  36. */
  37. public function testConvertWithMissedConverter()
  38. {
  39. $element = new \DOMElement('name');
  40. $composite = new Composite(['key' => $this->converter], 'type');
  41. $composite->convert($element, ['type' => 'missedKey']);
  42. }
  43. /**
  44. * @return void
  45. * @expectedException \InvalidArgumentException
  46. * @expectedExceptionMessage Converter named 'key' is expected to be an argument converter instance.
  47. */
  48. public function testConvertWithInvalidConverter()
  49. {
  50. $element = new \DOMElement('name');
  51. $std = new \stdClass();
  52. $composite = new Composite(['key' => $std], 'type');
  53. $composite->convert($element, ['type' => 'key']);
  54. }
  55. }