Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MaintenanceEnableCommandTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Symfony\Component\Console\Tester\CommandTester;
12 
13 class MaintenanceEnableCommandTest extends \PHPUnit\Framework\TestCase
14 {
18  private $maintenanceMode;
19 
23  private $ipValidator;
24 
28  private $command;
29 
30  public function setUp()
31  {
32  $this->maintenanceMode = $this->createMock(\Magento\Framework\App\MaintenanceMode::class);
33  $this->ipValidator = $this->createMock(\Magento\Setup\Validator\IpValidator::class);
34  $this->command = new MaintenanceEnableCommand($this->maintenanceMode, $this->ipValidator);
35  }
36 
43  public function testExecute(array $input, array $validatorMessages, $expectedMessage)
44  {
45  $return = isset($input['--ip']) ? ($input['--ip'] !== ['none'] ? $input['--ip'] : []) : [];
46  $this->maintenanceMode
47  ->expects($this->any())
48  ->method('getAddressInfo')
49  ->willReturn($return);
50  $this->ipValidator->expects($this->once())->method('validateIps')->willReturn($validatorMessages);
51  $tester = new CommandTester($this->command);
52  $tester->execute($input);
53  $this->assertEquals($expectedMessage, $tester->getDisplay());
54  }
55 
59  public function executeDataProvider()
60  {
61  return [
62  [
63  ['--ip' => ['127.0.0.1', '127.0.0.2']],
64  [],
65  'Enabled maintenance mode' . PHP_EOL .
66  'Set exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL
67  ],
68  [
69  ['--ip' => ['none']],
70  [],
71  'Enabled maintenance mode' . PHP_EOL .
72  'Set exempt IP-addresses: none' . PHP_EOL
73  ],
74  [
75  [],
76  [],
77  'Enabled maintenance mode' . PHP_EOL
78  ],
79  [
80  ['--ip' => ['127.0']],
81  ['Invalid IP 127.0'],
82  'Invalid IP 127.0' . PHP_EOL
83  ],
84  ];
85  }
86 }
testExecute(array $input, array $validatorMessages, $expectedMessage)