CommentTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\Model\Config\Parser;
  7. use Magento\Config\Model\Config\Parser\Comment;
  8. use Magento\Config\Model\Placeholder\PlaceholderInterface;
  9. use Magento\Framework\App\Filesystem\DirectoryList;
  10. use Magento\Framework\Filesystem;
  11. use Magento\Framework\Filesystem\Directory\ReadInterface;
  12. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  13. class CommentTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var PlaceholderInterface|MockObject
  17. */
  18. private $placeholderMock;
  19. /**
  20. * @var Filesystem|MockObject
  21. */
  22. private $fileSystemMock;
  23. /**
  24. * @var Comment
  25. */
  26. private $model;
  27. /**
  28. * @inheritdoc
  29. */
  30. protected function setUp()
  31. {
  32. $this->placeholderMock = $this->getMockBuilder(PlaceholderInterface::class)
  33. ->disableOriginalConstructor()
  34. ->getMockForAbstractClass();
  35. $this->fileSystemMock = $this->getMockBuilder(Filesystem::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $this->model = new Comment(
  39. $this->fileSystemMock,
  40. $this->placeholderMock
  41. );
  42. }
  43. public function testExecute()
  44. {
  45. $fileName = 'config.local.php';
  46. $directoryReadMock = $this->getMockBuilder(ReadInterface::class)
  47. ->disableOriginalConstructor()
  48. ->getMockForAbstractClass();
  49. $directoryReadMock->expects($this->once())
  50. ->method('readFile')
  51. ->with($fileName)
  52. ->willReturn(file_get_contents(__DIR__ . '/../_files/' . $fileName));
  53. $this->fileSystemMock->expects($this->once())
  54. ->method('getDirectoryRead')
  55. ->with(DirectoryList::CONFIG)
  56. ->willReturn($directoryReadMock);
  57. $this->placeholderMock->expects($this->any())
  58. ->method('restore')
  59. ->withConsecutive(
  60. ['CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD'],
  61. ['CONFIG__DEFAULT__SOME__PAYMENT__TOKEN']
  62. )
  63. ->willReturnOnConsecutiveCalls(
  64. 'some/payment/password',
  65. 'some/payment/token'
  66. );
  67. $this->assertEquals(
  68. $this->model->execute($fileName),
  69. [
  70. 'CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD' => 'some/payment/password',
  71. 'CONFIG__DEFAULT__SOME__PAYMENT__TOKEN' => 'some/payment/token'
  72. ]
  73. );
  74. }
  75. }