Skip to content

Commit

Permalink
Merge pull request #1846 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - develop
 - MAGETWO-85584: Add --no-update option to sampledata:deploy and remove commands #12663
 - MAGETWO-85539: fix adminhtml file attribute edit form #11267
  • Loading branch information
ishakhsuvarov authored Dec 13, 2017
2 parents eeed63e + 6692b5f commit 34c45c3
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 120 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Model/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function upload()
$result = $fileProcessor->saveTemporaryFile($this->scope . '[' . $this->getAttributeCode() . ']');

// Update tmp_name param. Required for attribute validation!
$result['tmp_name'] = $result['path'] . '/' . ltrim($result['file'], '/');
$result['tmp_name'] = ltrim($result['file'], '/');

$result['url'] = $fileProcessor->getViewUrl(
FileProcessor::TMP_DIR . '/' . ltrim($result['name'], '/'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testUpload()
'name' => $resultFileName,
'file' => $resultFileName,
'path' => $resultFilePath,
'tmp_name' => $resultFilePath . $resultFileName,
'tmp_name' => ltrim($resultFileName, '/'),
'url' => $resultFileUrl,
];

Expand Down
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

0 comments on commit 34c45c3

Please sign in to comment.