Skip to content

Add a --no-update option to sampledata:deploy and sampledata:remove commands #12359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command for deployment of Sample Data
*/
class SampleDataDeployCommand extends Command
{
const OPTION_NO_UPDATE = 'no-update';

/**
* @var \Magento\Framework\Filesystem
*/
Expand Down Expand Up @@ -66,6 +69,12 @@ protected function configure()
{
$this->setName('sampledata:deploy')
->setDescription('Deploy sample data modules');
$this->addOption(
self::OPTION_NO_UPDATE,
null,
InputOption::VALUE_NONE,
'Update composer.json without executing composer update'
);
parent::configure();
}

Expand All @@ -80,6 +89,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!empty($sampleDataPackages)) {
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
$commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1];
if ($input->getOption(self::OPTION_NO_UPDATE)) {
$commonArgs['--no-update'] = 1;
}
$packages = [];
foreach ($sampleDataPackages as $name => $version) {
$packages[] = "$name:$version";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\SampleData\Model\Dependency;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -22,6 +23,8 @@
*/
class SampleDataRemoveCommand extends Command
{
const OPTION_NO_UPDATE = 'no-update';

/**
* @var Filesystem
*/
Expand Down Expand Up @@ -69,6 +72,12 @@ protected function configure()
{
$this->setName('sampledata:remove')
->setDescription('Remove all sample data packages from composer.json');
$this->addOption(
self::OPTION_NO_UPDATE,
null,
InputOption::VALUE_NONE,
'Update composer.json without executing composer update'
);
parent::configure();
}

Expand All @@ -81,6 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!empty($sampleDataPackages)) {
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
$commonArgs = ['--working-dir' => $baseDir, '--no-interaction' => 1, '--no-progress' => 1];
if ($input->getOption(self::OPTION_NO_UPDATE)) {
$commonArgs['--no-update'] = 1;
}
$packages = array_keys($sampleDataPackages);
$arguments = array_merge(['command' => 'remove', 'packages' => $packages], $commonArgs);
$commandInput = new ArrayInput($arguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\SampleData\Test\Unit\Console\Command;

use Composer\Console\Application;
use Composer\Console\ApplicationFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterface;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\SampleData\Model\Dependency;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\ArrayInputFactory;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
abstract class AbstractSampleDataCommandTest extends TestCase
{
/**
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $directoryReadMock;

/**
* @var WriteInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $directoryWriteMock;

/**
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
*/
protected $filesystemMock;

/**
* @var Dependency|\PHPUnit_Framework_MockObject_MockObject
*/
protected $sampleDataDependencyMock;

/**
* @var ArrayInputFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $arrayInputFactoryMock;

/**
* @var Application|\PHPUnit_Framework_MockObject_MockObject
*/
protected $applicationMock;

/**
* @var ApplicationFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $applicationFactoryMock;

/**
* @return void
*/
protected function setUp()
{
$this->directoryReadMock = $this->createMock(ReadInterface::class);
$this->directoryWriteMock = $this->createMock(WriteInterface::class);
$this->filesystemMock = $this->createMock(Filesystem::class);
$this->sampleDataDependencyMock = $this->createMock(Dependency::class);
$this->arrayInputFactoryMock = $this->createMock(ArrayInputFactory::class);
$this->applicationMock = $this->createMock(Application::class);
$this->applicationFactoryMock = $this->createPartialMock(ApplicationFactory::class, ['create']);
}

/**
* @param array $sampleDataPackages Array in form [package_name => version_constraint]
* @param string $pathToComposerJson Fake path to composer.json
* @param int $appRunResult Composer exit code
* @param array $additionalComposerArgs Additional arguments that composer expects
*/
protected function setupMocks(
$sampleDataPackages,
$pathToComposerJson,
$appRunResult,
$additionalComposerArgs = []
) {
$this->directoryReadMock->expects($this->any())->method('getAbsolutePath')->willReturn($pathToComposerJson);
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT)->willReturn(
$this->directoryReadMock
);
$this->sampleDataDependencyMock->expects($this->any())->method('getSampleDataPackages')->willReturn(
$sampleDataPackages
);
$this->arrayInputFactoryMock->expects($this->never())->method('create');

$this->applicationMock->expects($this->any())
->method('run')
->with(
new ArrayInput(
array_merge(
$this->expectedComposerArguments(
$sampleDataPackages,
$pathToComposerJson
),
$additionalComposerArgs
)
),
$this->anything()
)
->willReturn($appRunResult);

if (($appRunResult !== 0) && !empty($sampleDataPackages)) {
$this->applicationMock->expects($this->once())->method('resetComposer')->willReturnSelf();
}

$this->applicationFactoryMock->expects($this->any())
->method('create')
->willReturn($this->applicationMock);
}

/**
* Expected arguments for composer based on sample data packages and composer.json path
*
* @param array $sampleDataPackages
* @param string $pathToComposerJson
* @return array
*/
abstract protected function expectedComposerArguments(
array $sampleDataPackages,
string $pathToComposerJson
) : array;
}
Loading