FileReaderTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit\DeploymentConfig;
  7. use Magento\Framework\App\DeploymentConfig\FileReader;
  8. use Magento\Framework\App\Filesystem\DirectoryList;
  9. use Magento\Framework\Config\File\ConfigFilePool;
  10. use Magento\Framework\Filesystem\DriverInterface;
  11. use Magento\Framework\Filesystem\DriverPool;
  12. use \PHPUnit_Framework_MockObject_MockObject as Mock;
  13. /**
  14. * @inheritdoc
  15. */
  16. class FileReaderTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var FileReader
  20. */
  21. private $model;
  22. /**
  23. * @var DirectoryList|Mock
  24. */
  25. private $dirListMock;
  26. /**
  27. * @var DriverPool|Mock
  28. */
  29. private $driverPoolMock;
  30. /**
  31. * @var ConfigFilePool|Mock
  32. */
  33. private $configFilePool;
  34. /**
  35. * @var DriverInterface|Mock
  36. */
  37. private $driverMock;
  38. protected function setUp()
  39. {
  40. $this->dirListMock = $this->getMockBuilder(DirectoryList::class)
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $this->driverPoolMock = $this->getMockBuilder(DriverPool::class)
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->configFilePool = $this->getMockBuilder(ConfigFilePool::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->driverMock = $this->getMockBuilder(DriverInterface::class)
  50. ->getMockForAbstractClass();
  51. $this->model = new FileReader(
  52. $this->dirListMock,
  53. $this->driverPoolMock,
  54. $this->configFilePool
  55. );
  56. }
  57. public function testLoad()
  58. {
  59. $fileKey = 'configKeyOne';
  60. $this->dirListMock->expects($this->exactly(2))
  61. ->method('getPath')
  62. ->with(DirectoryList::CONFIG)
  63. ->willReturn(__DIR__ . '/_files');
  64. $this->driverPoolMock->expects($this->exactly(2))
  65. ->method('getDriver')
  66. ->with(DriverPool::FILE)
  67. ->willReturn($this->driverMock);
  68. $this->configFilePool->expects($this->exactly(2))
  69. ->method('getPath')
  70. ->willReturnMap([['configKeyOne', 'config.php']]);
  71. $this->driverMock->expects($this->exactly(2))
  72. ->method('isExists')
  73. ->willReturnOnConsecutiveCalls(true, false);
  74. $this->configFilePool
  75. ->expects($this->any())
  76. ->method('getPath')
  77. ->willReturnMap([['configKeyOne', 'config.php']]);
  78. $this->assertSame(['fooKey' => 'foo', 'barKey' => 'bar'], $this->model->load($fileKey));
  79. $this->assertSame([], $this->model->load($fileKey));
  80. }
  81. }