123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Config\Test\Unit\Console\Command;
- use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
- use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
- use Magento\Config\Console\Command\ConfigSetCommand;
- use Magento\Config\Console\Command\EmulatedAdminhtmlAreaProcessor;
- use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
- use Magento\Framework\App\DeploymentConfig;
- use Magento\Framework\Console\Cli;
- use Magento\Framework\Exception\ValidatorException;
- use PHPUnit_Framework_MockObject_MockObject as Mock;
- use Symfony\Component\Console\Tester\CommandTester;
- /**
- * Test for ConfigSetCommand.
- *
- * @see ConfigSetCommand
- */
- class ConfigSetCommandTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ConfigSetCommand
- */
- private $command;
- /**
- * @var EmulatedAdminhtmlAreaProcessor|Mock
- */
- private $emulatedAreProcessorMock;
- /**
- * @var ChangeDetector|Mock
- */
- private $changeDetectorMock;
- /**
- * @var ProcessorFacadeFactory|Mock
- */
- private $processorFacadeFactoryMock;
- /**
- * @var DeploymentConfig|Mock
- */
- private $deploymentConfigMock;
- /**
- * @var ProcessorFacade|Mock
- */
- private $processorFacadeMock;
- /**
- * @inheritdoc
- */
- protected function setUp()
- {
- $this->emulatedAreProcessorMock = $this->getMockBuilder(EmulatedAdminhtmlAreaProcessor::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->changeDetectorMock = $this->getMockBuilder(ChangeDetector::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->processorFacadeFactoryMock = $this->getMockBuilder(ProcessorFacadeFactory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->processorFacadeMock = $this->getMockBuilder(ProcessorFacade::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->command = new ConfigSetCommand(
- $this->emulatedAreProcessorMock,
- $this->changeDetectorMock,
- $this->processorFacadeFactoryMock,
- $this->deploymentConfigMock
- );
- }
- public function testExecute()
- {
- $this->deploymentConfigMock->expects($this->once())
- ->method('isAvailable')
- ->willReturn(true);
- $this->changeDetectorMock->expects($this->once())
- ->method('hasChanges')
- ->willReturn(false);
- $this->processorFacadeFactoryMock->expects($this->once())
- ->method('create')
- ->willReturn($this->processorFacadeMock);
- $this->processorFacadeMock->expects($this->once())
- ->method('processWithLockTarget')
- ->willReturn('Some message');
- $this->emulatedAreProcessorMock->expects($this->once())
- ->method('process')
- ->willReturnCallback(function ($function) {
- return $function();
- });
- $tester = new CommandTester($this->command);
- $tester->execute([
- ConfigSetCommand::ARG_PATH => 'test/test/test',
- ConfigSetCommand::ARG_VALUE => 'value'
- ]);
- $this->assertContains(
- __('Some message')->render(),
- $tester->getDisplay()
- );
- $this->assertSame(Cli::RETURN_SUCCESS, $tester->getStatusCode());
- }
- public function testExecuteMagentoUninstalled()
- {
- $this->deploymentConfigMock->expects($this->once())
- ->method('isAvailable')
- ->willReturn(false);
- $this->emulatedAreProcessorMock->expects($this->never())
- ->method('process');
- $tester = new CommandTester($this->command);
- $tester->execute([
- ConfigSetCommand::ARG_PATH => 'test/test/test',
- ConfigSetCommand::ARG_VALUE => 'value'
- ]);
- $this->assertContains(
- __('You cannot run this command because the Magento application is not installed.')->render(),
- $tester->getDisplay()
- );
- $this->assertSame(Cli::RETURN_FAILURE, $tester->getStatusCode());
- }
- public function testExecuteNeedsRegeneration()
- {
- $this->deploymentConfigMock->expects($this->once())
- ->method('isAvailable')
- ->willReturn(true);
- $this->changeDetectorMock->expects($this->once())
- ->method('hasChanges')
- ->willReturn(true);
- $this->emulatedAreProcessorMock->expects($this->never())
- ->method('process');
- $tester = new CommandTester($this->command);
- $tester->execute([
- ConfigSetCommand::ARG_PATH => 'test/test/test',
- ConfigSetCommand::ARG_VALUE => 'value'
- ]);
- $this->assertContains(
- __('This command is unavailable right now.')->render(),
- $tester->getDisplay()
- );
- $this->assertSame(Cli::RETURN_FAILURE, $tester->getStatusCode());
- }
- public function testExecuteWithException()
- {
- $this->deploymentConfigMock->expects($this->once())
- ->method('isAvailable')
- ->willReturn(true);
- $this->changeDetectorMock->expects($this->once())
- ->method('hasChanges')
- ->willReturn(false);
- $this->emulatedAreProcessorMock->expects($this->once())
- ->method('process')
- ->willThrowException(new ValidatorException(__('The "test/test/test" path does not exists')));
- $tester = new CommandTester($this->command);
- $tester->execute([
- ConfigSetCommand::ARG_PATH => 'test/test/test',
- ConfigSetCommand::ARG_VALUE => 'value'
- ]);
- $this->assertContains(
- __('The "test/test/test" path does not exists')->render(),
- $tester->getDisplay()
- );
- $this->assertSame(Cli::RETURN_FAILURE, $tester->getStatusCode());
- }
- }
|