ConfigStatusCommandTest.php 2.07 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Deploy\Test\Unit\Console\Command\App;

use Magento\Deploy\Console\Command\App\ConfigStatusCommand;
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Tester\CommandTester;

/**
 * @inheritdoc
 */
class ConfigStatusCommandTest extends \PHPUnit\Framework\TestCase
{

    /**
     * @var ConfigStatusCommand
     */
    private $command;
    /**
     * @var ChangeDetector
     */
    private $changeDetector;

    /**
     * @inheritdoc
     */
    protected function setUp()
    {
        $this->changeDetector = $this->getMockBuilder(ChangeDetector::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->command = new ConfigStatusCommand($this->changeDetector);
    }

    /**
     * @param bool $hasChanges
     * @param string $expectedMessage
     * @param int $expectedCode
     *
     * @dataProvider executeDataProvider
     */
    public function testExecute(bool $hasChanges, $expectedMessage, $expectedCode)
    {
        $this->changeDetector->expects($this->once())
            ->method('hasChanges')
            ->will($this->returnValue($hasChanges));

        $tester = new CommandTester($this->command);
        $tester->execute([]);

        $this->assertEquals($expectedMessage, $tester->getDisplay());
        $this->assertSame($expectedCode, $tester->getStatusCode());
    }

    /**
     * @return array
     */
    public function executeDataProvider()
    {
        return [
            'Config is up to date' => [
                false,
                'Config files are up to date.' . PHP_EOL,
                Cli::RETURN_SUCCESS
            ],
            'Config needs update' => [
                true,
                'Config files have changed. ' .
                'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL,
                ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED,
            ],
        ];
    }
}