ConfigStatusCommandTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Deploy\Console\Command\App\ConfigStatusCommand;
  8. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  9. use Magento\Framework\Console\Cli;
  10. use Symfony\Component\Console\Tester\CommandTester;
  11. /**
  12. * @inheritdoc
  13. */
  14. class ConfigStatusCommandTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var ConfigStatusCommand
  18. */
  19. private $command;
  20. /**
  21. * @var ChangeDetector
  22. */
  23. private $changeDetector;
  24. /**
  25. * @inheritdoc
  26. */
  27. protected function setUp()
  28. {
  29. $this->changeDetector = $this->getMockBuilder(ChangeDetector::class)
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->command = new ConfigStatusCommand($this->changeDetector);
  33. }
  34. /**
  35. * @param bool $hasChanges
  36. * @param string $expectedMessage
  37. * @param int $expectedCode
  38. *
  39. * @dataProvider executeDataProvider
  40. */
  41. public function testExecute(bool $hasChanges, $expectedMessage, $expectedCode)
  42. {
  43. $this->changeDetector->expects($this->once())
  44. ->method('hasChanges')
  45. ->will($this->returnValue($hasChanges));
  46. $tester = new CommandTester($this->command);
  47. $tester->execute([]);
  48. $this->assertEquals($expectedMessage, $tester->getDisplay());
  49. $this->assertSame($expectedCode, $tester->getStatusCode());
  50. }
  51. /**
  52. * @return array
  53. */
  54. public function executeDataProvider()
  55. {
  56. return [
  57. 'Config is up to date' => [
  58. false,
  59. 'Config files are up to date.' . PHP_EOL,
  60. Cli::RETURN_SUCCESS
  61. ],
  62. 'Config needs update' => [
  63. true,
  64. 'Config files have changed. ' .
  65. 'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL,
  66. ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED,
  67. ],
  68. ];
  69. }
  70. }