ReaderTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\Address\Config;
  7. class ReaderTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Customer\Model\Address\Config\Reader
  11. */
  12. protected $_model;
  13. /**
  14. * @var \Magento\Framework\Config\FileResolverInterface|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_fileResolverMock;
  17. /**
  18. * @var \Magento\Customer\Model\Address\Config\Converter|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_converter;
  21. /**
  22. * @var \Magento\Customer\Model\Address\Config\SchemaLocator
  23. */
  24. protected $_schemaLocator;
  25. /**
  26. * @var \Magento\Framework\Config\ValidationStateInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $_validationState;
  29. protected function setUp()
  30. {
  31. $this->_fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
  32. $this->_fileResolverMock->expects(
  33. $this->once()
  34. )->method(
  35. 'get'
  36. )->with(
  37. 'address_formats.xml',
  38. 'scope'
  39. )->will(
  40. $this->returnValue(
  41. [
  42. file_get_contents(__DIR__ . '/_files/formats_one.xml'),
  43. file_get_contents(__DIR__ . '/_files/formats_two.xml'),
  44. ]
  45. )
  46. );
  47. $this->_converter = $this->createPartialMock(
  48. \Magento\Customer\Model\Address\Config\Converter::class,
  49. ['convert']
  50. );
  51. $moduleReader = $this->createPartialMock(\Magento\Framework\Module\Dir\Reader::class, ['getModuleDir']);
  52. $moduleReader->expects(
  53. $this->once()
  54. )->method(
  55. 'getModuleDir'
  56. )->with(
  57. 'etc',
  58. 'Magento_Customer'
  59. )->will(
  60. $this->returnValue('stub')
  61. );
  62. $this->_schemaLocator = new \Magento\Customer\Model\Address\Config\SchemaLocator($moduleReader);
  63. $this->_validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
  64. $this->_validationState->expects($this->any())
  65. ->method('isValidationRequired')
  66. ->willReturn(false);
  67. $this->_model = new \Magento\Customer\Model\Address\Config\Reader(
  68. $this->_fileResolverMock,
  69. $this->_converter,
  70. $this->_schemaLocator,
  71. $this->_validationState
  72. );
  73. }
  74. public function testRead()
  75. {
  76. $expectedResult = new \stdClass();
  77. $constraint = function (\DOMDocument $actual) {
  78. try {
  79. $expected = __DIR__ . '/_files/formats_merged.xml';
  80. \PHPUnit\Framework\Assert::assertXmlStringEqualsXmlFile($expected, $actual->saveXML());
  81. return true;
  82. } catch (\PHPUnit\Framework\AssertionFailedError $e) {
  83. return false;
  84. }
  85. };
  86. $this->_converter->expects(
  87. $this->once()
  88. )->method(
  89. 'convert'
  90. )->with(
  91. $this->callback($constraint)
  92. )->will(
  93. $this->returnValue($expectedResult)
  94. );
  95. $this->assertSame($expectedResult, $this->_model->read('scope'));
  96. }
  97. }