ApplicationDumpCommandTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Console\Command;
  7. use Magento\Config\Model\Config\Export\Comment;
  8. use Magento\Deploy\Console\Command\App\ApplicationDumpCommand;
  9. use Magento\Deploy\Model\DeploymentConfig\Hash;
  10. use Magento\Framework\App\Config\Reader\Source\SourceInterface;
  11. use Magento\Framework\App\DeploymentConfig\Writer;
  12. use Magento\Framework\Config\File\ConfigFilePool;
  13. use Magento\Framework\Console\Cli;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. /**
  17. * Test command for dump application state
  18. */
  19. class ApplicationDumpCommandTest extends \PHPUnit\Framework\TestCase
  20. {
  21. /**
  22. * @var InputInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $input;
  25. /**
  26. * @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $output;
  29. /**
  30. * @var Writer|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $writer;
  33. /**
  34. * @var SourceInterface|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. private $source;
  37. /**
  38. * @var SourceInterface|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. private $sourceEnv;
  41. /**
  42. * @var Hash|\PHPUnit_Framework_MockObject_MockObject
  43. */
  44. private $configHashMock;
  45. /**
  46. * @var Comment|\PHPUnit_Framework_MockObject_MockObject
  47. */
  48. private $commentMock;
  49. /**
  50. * @var ApplicationDumpCommand
  51. */
  52. private $command;
  53. public function setUp()
  54. {
  55. $this->configHashMock = $this->getMockBuilder(Hash::class)
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->input = $this->getMockBuilder(InputInterface::class)
  59. ->getMockForAbstractClass();
  60. $this->output = $this->getMockBuilder(OutputInterface::class)
  61. ->getMockForAbstractClass();
  62. $this->writer = $this->getMockBuilder(Writer::class)
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $this->source = $this->getMockBuilder(SourceInterface::class)
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $this->sourceEnv = $this->getMockBuilder(SourceInterface::class)
  69. ->disableOriginalConstructor()
  70. ->getMock();
  71. $this->commentMock = $this->getMockBuilder(Comment::class)
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $this->command = new ApplicationDumpCommand(
  75. $this->writer,
  76. [
  77. [
  78. 'namespace' => 'system',
  79. 'source' => $this->source,
  80. 'pool' => ConfigFilePool::APP_CONFIG,
  81. 'comment' => $this->commentMock
  82. ],
  83. [
  84. 'namespace' => 'system',
  85. 'source' => $this->sourceEnv,
  86. 'pool' => ConfigFilePool::APP_ENV
  87. ]
  88. ],
  89. $this->configHashMock
  90. );
  91. }
  92. public function testExport()
  93. {
  94. $dump = [
  95. 'system' => ['systemDATA']
  96. ];
  97. $this->configHashMock->expects($this->once())
  98. ->method('regenerate');
  99. $this->source
  100. ->expects($this->once())
  101. ->method('get')
  102. ->willReturn(['systemDATA']);
  103. $this->sourceEnv
  104. ->expects($this->once())
  105. ->method('get')
  106. ->willReturn(['systemDATA']);
  107. $this->commentMock->expects($this->once())
  108. ->method('get')
  109. ->willReturn('Some comment message');
  110. $this->writer->expects($this->exactly(2))
  111. ->method('saveConfig')
  112. ->withConsecutive(
  113. [[ConfigFilePool::APP_CONFIG => $dump]],
  114. [[ConfigFilePool::APP_ENV => $dump]]
  115. );
  116. $this->output->expects($this->exactly(2))
  117. ->method('writeln')
  118. ->withConsecutive(
  119. [['system' => 'Some comment message']],
  120. ['<info>Done. Config types dumped: system</info>']
  121. );
  122. $method = new \ReflectionMethod(ApplicationDumpCommand::class, 'execute');
  123. $method->setAccessible(true);
  124. $this->assertEquals(
  125. Cli::RETURN_SUCCESS,
  126. $method->invokeArgs(
  127. $this->command,
  128. [$this->input, $this->output]
  129. )
  130. );
  131. }
  132. }