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