SensitiveConfigSetCommandTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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\App;
  7. use Magento\Config\App\Config\Type\System;
  8. use Magento\Config\Console\Command\EmulatedAdminhtmlAreaProcessor;
  9. use Magento\Deploy\Console\Command\App\SensitiveConfigSet\SensitiveConfigSetFacade;
  10. use Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand;
  11. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  12. use Magento\Deploy\Model\DeploymentConfig\Hash;
  13. use Magento\Framework\Console\Cli;
  14. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  15. use Symfony\Component\Console\Tester\CommandTester;
  16. /**
  17. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  18. */
  19. class SensitiveConfigSetCommandTest extends \PHPUnit\Framework\TestCase
  20. {
  21. /**
  22. * @var SensitiveConfigSetFacade|MockObject
  23. */
  24. private $facadeMock;
  25. /**
  26. * @var ChangeDetector|MockObject
  27. */
  28. private $changeDetectorMock;
  29. /**
  30. * @var Hash|MockObject
  31. */
  32. private $hashMock;
  33. /**
  34. * @var EmulatedAdminhtmlAreaProcessor|MockObject
  35. */
  36. private $emulatedAreaProcessorMock;
  37. /**
  38. * @var SensitiveConfigSetCommand
  39. */
  40. private $model;
  41. /**
  42. * @inheritdoc
  43. */
  44. public function setUp()
  45. {
  46. $this->facadeMock = $this->getMockBuilder(SensitiveConfigSetFacade::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->changeDetectorMock = $this->getMockBuilder(ChangeDetector::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->hashMock = $this->getMockBuilder(Hash::class)
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->emulatedAreaProcessorMock = $this->getMockBuilder(EmulatedAdminhtmlAreaProcessor::class)
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->model = new SensitiveConfigSetCommand(
  59. $this->facadeMock,
  60. $this->changeDetectorMock,
  61. $this->hashMock,
  62. $this->emulatedAreaProcessorMock
  63. );
  64. }
  65. public function testExecute()
  66. {
  67. $this->changeDetectorMock->expects($this->once())
  68. ->method('hasChanges')
  69. ->willReturn(false);
  70. $this->emulatedAreaProcessorMock->expects($this->once())
  71. ->method('process');
  72. $this->hashMock->expects($this->once())
  73. ->method('regenerate')
  74. ->with(System::CONFIG_TYPE);
  75. $tester = new CommandTester($this->model);
  76. $tester->execute([]);
  77. $this->assertEquals(
  78. Cli::RETURN_SUCCESS,
  79. $tester->getStatusCode()
  80. );
  81. }
  82. public function testExecuteNeedsRegeneration()
  83. {
  84. $this->changeDetectorMock->expects($this->once())
  85. ->method('hasChanges')
  86. ->willReturn(true);
  87. $this->emulatedAreaProcessorMock->expects($this->never())
  88. ->method('process');
  89. $this->hashMock->expects($this->never())
  90. ->method('regenerate');
  91. $tester = new CommandTester($this->model);
  92. $tester->execute([]);
  93. $this->assertEquals(
  94. Cli::RETURN_FAILURE,
  95. $tester->getStatusCode()
  96. );
  97. $this->assertContains(
  98. 'This command is unavailable right now.',
  99. $tester->getDisplay()
  100. );
  101. }
  102. public function testExecuteWithException()
  103. {
  104. $this->changeDetectorMock->expects($this->once())
  105. ->method('hasChanges')
  106. ->willReturn(false);
  107. $this->emulatedAreaProcessorMock->expects($this->once())
  108. ->method('process')
  109. ->willThrowException(new \Exception('Some exception'));
  110. $tester = new CommandTester($this->model);
  111. $tester->execute([]);
  112. $this->assertEquals(
  113. Cli::RETURN_FAILURE,
  114. $tester->getStatusCode()
  115. );
  116. $this->assertContains(
  117. 'Some exception',
  118. $tester->getDisplay()
  119. );
  120. }
  121. }