Skip to content

Commit

Permalink
Merge pull request #1525 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests2.2
  • Loading branch information
vrann authored Sep 27, 2017
2 parents d5cf0c3 + c460b37 commit fa2439c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
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\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -22,10 +23,16 @@ class DevTestsRunCommand extends Command
*/
const INPUT_ARG_TYPE = 'type';

/**
* PHPUnit arguments parameter
*/
const INPUT_OPT_COMMAND_ARGUMENTS = 'arguments';
const INPUT_OPT_COMMAND_ARGUMENTS_SHORT = 'c';

/**
* command name
*/
const COMMAND_NAME = 'dev:tests:run';
const COMMAND_NAME = 'dev:tests:run';

/**
* Maps types (from user input) to phpunit test names
Expand Down Expand Up @@ -56,6 +63,13 @@ protected function configure()
'Type of test to run. Available types: ' . implode(', ', array_keys($this->types)),
'default'
);
$this->addOption(
self::INPUT_OPT_COMMAND_ARGUMENTS,
self::INPUT_OPT_COMMAND_ARGUMENTS_SHORT,
InputOption::VALUE_REQUIRED,
'Additional arguments for PHPUnit. Example: "-c\'--filter=MyTest\'" (no spaces)',
''
);

parent::configure();
}
Expand Down Expand Up @@ -87,6 +101,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dirName = realpath(BP . '/dev/tests/' . $dir);
chdir($dirName);
$command = PHP_BINARY . ' ' . BP . '/' . $vendorDir . '/phpunit/phpunit/phpunit ' . $options;
if ($commandArguments = $input->getOption(self::INPUT_OPT_COMMAND_ARGUMENTS)) {
$command .= ' ' . $commandArguments;
}
$message = $dirName . '> ' . $command;
$output->writeln(['', str_pad("---- {$message} ", 70, '-'), '']);
passthru($command, $returnVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ public function testExecuteBadType()
$commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']);
$this->assertContains('Invalid type: "bad"', $commandTester->getDisplay());
}

public function testPassArgumentsToPHPUnit()
{
$commandTester = new CommandTester($this->command);
$commandTester->execute(
[
DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
'-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
]
);
$this->assertContains(
'phpunit --list-suites',
$commandTester->getDisplay(),
'Parameters should be passed to PHPUnit'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testPrepareDataSource()
{
$itemName = 'itemName';
$oldItemValue = "itemValue\n";
$newItemValue = 'itemValue<br/>';
$newItemValue = "itemValue<br />\n";
$dataSource = [
'data' => [
'items' => [
Expand All @@ -57,7 +57,7 @@ public function testPrepareDataSource()
];

$this->model->setData('name', $itemName);
$this->escaper->expects($this->once())->method('escapeHtml')->with($newItemValue)->willReturnArgument(0);
$this->escaper->expects($this->any())->method('escapeHtml')->with($oldItemValue)->willReturnArgument(0);
$dataSource = $this->model->prepareDataSource($dataSource);
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$item[$this->getData('name')] = $this->escaper->escapeHtml(
str_replace("\n", '<br/>', $item[$this->getData('name')])
);
$item[$this->getData('name')] = nl2br($this->escaper->escapeHtml($item[$this->getData('name')]));
}
}

Expand Down
15 changes: 13 additions & 2 deletions setup/src/Magento/Setup/Console/Command/BackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class BackupCommand extends AbstractSetupCommand
*/
private $deploymentConfig;

/**
* The initial maintenance mode state
* @var bool
*/
private $maintenanceModeInitialState;

/**
* Constructor
*
Expand All @@ -73,6 +79,7 @@ public function __construct(
$this->maintenanceMode = $maintenanceMode;
$this->backupRollbackFactory = $this->objectManager->get(\Magento\Framework\Setup\BackupRollbackFactory::class);
$this->deploymentConfig = $deploymentConfig;
$this->maintenanceModeInitialState = $this->maintenanceMode->isOn();
parent::__construct();
}

Expand Down Expand Up @@ -109,6 +116,7 @@ protected function configure()

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -147,8 +155,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>' . $e->getMessage() . '</error>');
$returnValue = \Magento\Framework\Console\Cli::RETURN_FAILURE;
} finally {
$output->writeln('<info>Disabling maintenance mode</info>');
$this->maintenanceMode->set(false);
// Only disable maintenace mode if it wasn't turned on before
if (!$this->maintenanceModeInitialState) {
$output->writeln('<info>Disabling maintenance mode</info>');
$this->maintenanceMode->set(false);
}
}
return $returnValue;
}
Expand Down

0 comments on commit fa2439c

Please sign in to comment.