Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetModeCommandTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Symfony\Component\Console\Tester\CommandTester;
11 
15 class SetModeCommandTest extends \PHPUnit\Framework\TestCase
16 {
20  private $modeMock;
21 
25  private $command;
26 
30  private $objectManagerMock;
31 
32  protected function setUp()
33  {
34  $this->objectManagerMock = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
35  $this->modeMock = $this->createMock(\Magento\Deploy\Model\Mode::class);
36 
37  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38  $this->command = $objectManager->getObject(
39  \Magento\Deploy\Console\Command\SetModeCommand::class,
40  ['objectManager' => $this->objectManagerMock]
41  );
42 
43  $this->objectManagerMock->expects($this->once())->method('create')->willReturn($this->modeMock);
44  }
45 
46  public function testSetProductionMode()
47  {
48  $this->modeMock->expects($this->once())->method('enableProductionMode');
49 
50  $tester = new CommandTester($this->command);
51  $tester->execute(['mode' => 'production']);
52  $this->assertContains(
53  "production mode",
54  $tester->getDisplay()
55  );
56  }
57 
58  public function testSetDeveloperMode()
59  {
60  $this->modeMock->expects($this->once())->method('enableDeveloperMode');
61 
62  $tester = new CommandTester($this->command);
63  $tester->execute(['mode' => 'developer']);
64  $this->assertContains(
65  "developer mode",
66  $tester->getDisplay()
67  );
68  }
69 
70  public function testSetDefaultMode()
71  {
72  $this->modeMock->expects($this->once())->method('enableDefaultMode');
73 
74  $tester = new CommandTester($this->command);
75  $tester->execute(['mode' => 'default']);
76  $this->assertContains(
77  "default mode",
78  $tester->getDisplay()
79  );
80  }
81 
83  {
84  $this->modeMock->expects($this->once())->method('enableProductionModeMinimal');
85 
86  $tester = new CommandTester($this->command);
87  $tester->execute(['mode' => 'production', '--skip-compilation' => true]);
88  $this->assertContains(
89  "production mode",
90  $tester->getDisplay()
91  );
92  }
93 
94  public function testSetInvalidMode()
95  {
96  $tester = new CommandTester($this->command);
97  $tester->execute(['mode' => 'invalid-mode']);
98  $this->assertContains(
99  'The mode can\'t be switched to "invalid-mode".',
100  $tester->getDisplay()
101  );
102  }
103 }
$objectManager
Definition: bootstrap.php:17