FileResolverTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Widget\Test\Unit\Model\Config;
  7. use Magento\Framework\Component\ComponentRegistrar;
  8. use \Magento\Widget\Model\Config\FileResolver;
  9. class FileResolverTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var FileResolver
  13. */
  14. private $object;
  15. /**
  16. * @var \Magento\Framework\Module\Dir\Reader|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $moduleReader;
  19. /**
  20. * @var \Magento\Framework\Config\FileIteratorFactory|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $factory;
  23. /**
  24. * @var \Magento\Framework\Component\DirSearch|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $componentDirSearch;
  27. protected function setUp()
  28. {
  29. $this->moduleReader = $this->createMock(\Magento\Framework\Module\Dir\Reader::class);
  30. $this->factory = $this->createMock(\Magento\Framework\Config\FileIteratorFactory::class);
  31. $this->componentDirSearch = $this->createMock(\Magento\Framework\Component\DirSearch::class);
  32. $this->object = new FileResolver($this->moduleReader, $this->factory, $this->componentDirSearch);
  33. }
  34. public function testGetGlobal()
  35. {
  36. $expected = new \stdClass();
  37. $this->moduleReader
  38. ->expects($this->once())
  39. ->method('getConfigurationFiles')
  40. ->with('file')
  41. ->willReturn($expected);
  42. $this->assertSame($expected, $this->object->get('file', 'global'));
  43. }
  44. public function testGetDesign()
  45. {
  46. $expected = new \stdClass();
  47. $this->componentDirSearch->expects($this->once())
  48. ->method('collectFiles')
  49. ->with(ComponentRegistrar::THEME, 'etc/file')
  50. ->will($this->returnValue(['test']));
  51. $this->factory->expects($this->once())->method('create')->with(['test'])->willReturn($expected);
  52. $this->assertSame($expected, $this->object->get('file', 'design'));
  53. }
  54. public function testGetDefault()
  55. {
  56. $expected = new \stdClass();
  57. $this->factory->expects($this->once())->method('create')->with([])->willReturn($expected);
  58. $this->assertSame($expected, $this->object->get('file', 'unknown'));
  59. }
  60. }