Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShellTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class ShellTest extends \PHPUnit\Framework\TestCase
13 {
15  private $loggerMock;
16 
18  private $driverMock;
19 
21  private $model;
22 
23  public function setUp()
24  {
25  $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
26  ->disableOriginalConstructor()
27  ->getMock();
28  $this->driverMock = $this->getMockBuilder(\Magento\Framework\Shell\Driver::class)
29  ->disableOriginalConstructor()
30  ->getMock();
31  $this->model = new Shell(
32  $this->driverMock,
33  $this->loggerMock
34  );
35  }
36 
37  public function testExecuteSuccess()
38  {
39  $output = 'success';
40  $exitCode = 0;
41  $command = 'escaped command';
42  $logEntry = $command . PHP_EOL . $output;
43 
44  $successfulResponse = new Response(
45  [
46  'output' => $output,
47  'exit_code' => $exitCode,
48  'escaped_command' => $command
49  ]
50  );
51  $this->driverMock->expects($this->once())->method('execute')->willReturn($successfulResponse);
52  $this->loggerMock->expects($this->once())->method('info')->with($logEntry);
53  $this->assertEquals($output, $this->model->execute($command, []));
54  }
55 
56  public function testExecuteFailure()
57  {
58  $output = 'failure';
59  $exitCode = 1;
60  $command = 'escaped command';
61  $logEntry = $command . PHP_EOL . $output;
62 
63  $response = new Response(
64  [
65  'output' => $output,
66  'exit_code' => $exitCode,
67  'escaped_command' => $command
68  ]
69  );
70  $this->driverMock->expects($this->once())->method('execute')->willReturn($response);
71  $this->loggerMock->expects($this->once())->method('error')->with($logEntry);
72  $this->expectException(LocalizedException::class);
73  $this->expectExceptionMessage("Command returned non-zero exit code:\n`$command`");
74  $this->model->execute($command, []);
75  }
76 }
$response
Definition: 404.php:11