9 class ShellTest extends \PHPUnit\Framework\TestCase
23 $this->logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
24 ->disableOriginalConstructor()
26 $this->commandRenderer = new \Magento\Framework\Shell\CommandRenderer();
39 $this->expectOutputString(
'');
41 $actualResult =
$shell->execute($command, $commandArgs);
42 $this->assertEquals($expectedResult, $actualResult);
51 public function testExecute($command, $commandArgs, $expectedResult)
54 new \
Magento\Framework\
Shell($this->commandRenderer, $this->logger),
68 public function testExecuteLog($command, $commandArgs, $expectedResult, $expectedLogRecords)
70 $quoteChar = substr(escapeshellarg(
' '), 0, 1);
72 foreach ($expectedLogRecords as $logRecordIndex => $expectedLogMessage) {
73 $expectedLogMessage = str_replace(
'`', $quoteChar, $expectedLogMessage);
74 $this->logger->expects($this->at($logRecordIndex))
76 ->with($expectedLogMessage);
79 new \
Magento\Framework\
Shell($this->commandRenderer, $this->logger),
93 'STDOUT' => [
'php -r %s', [
'echo 27181;'],
'27181', [
'php -r `echo 27181;` 2>&1',
'27181']],
96 [
'fwrite(STDERR, 27182);'],
98 [
'php -r `fwrite(STDERR, 27182);` 2>&1',
'27182'],
100 'piping STDERR -> STDOUT' => [
102 'php -r %s|php -r %s',
103 [
'fwrite(STDERR, 27183);',
'echo fgets(STDIN);'],
105 [
'php -r `fwrite(STDERR, 27183);` 2>&1|php -r `echo fgets(STDIN);` 2>&1',
'27183'],
107 'piping STDERR -> STDERR' => [
108 'php -r %s | php -r %s',
109 [
'fwrite(STDERR, 27184);',
'fwrite(STDERR, fgets(STDIN));'],
111 [
'php -r `fwrite(STDERR, 27184);` 2>&1 | php -r `fwrite(STDERR, fgets(STDIN));` 2>&1',
'27184'],
123 $shell = new \Magento\Framework\Shell($this->commandRenderer, $this->logger);
124 $shell->execute(
'non_existing_command');
137 $commandArgs[count($commandArgs) - 1] .=
' exit(42);';
139 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
140 $this->assertInstanceOf(
'Exception', $e->getPrevious());
141 $this->assertEquals($expectedError, $e->getPrevious()->getMessage());
142 $this->assertEquals(42, $e->getPrevious()->getCode());
_testExecuteCommand(\Magento\Framework\Shell $shell, $command, $commandArgs, $expectedResult)
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
testExecute($command, $commandArgs, $expectedResult)
testExecuteFailureDetails($command, $commandArgs, $expectedError)
testExecuteLog($command, $commandArgs, $expectedResult, $expectedLogRecords)