Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UninstallCommandTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Symfony\Component\Console\Tester\CommandTester;
13 
14 class UninstallCommandTest extends \PHPUnit\Framework\TestCase
15 {
19  private $installerFactory;
20 
24  private $installer;
25 
29  private $command;
30 
31  public function setUp()
32  {
33  $this->installerFactory = $this->createMock(\Magento\Setup\Model\InstallerFactory::class);
34  $this->installer = $this->createMock(\Magento\Setup\Model\Installer::class);
35  $this->command = new UninstallCommand($this->installerFactory);
36  }
37 
38  public function testExecuteInteractionYes()
39  {
40  $this->installer->expects($this->once())->method('uninstall');
41  $this->installerFactory->expects($this->once())->method('create')->will($this->returnValue($this->installer));
42 
43  $this->checkInteraction(true);
44  }
45 
46  public function testExecuteInteractionNo()
47  {
48  $this->installer->expects($this->exactly(0))->method('uninstall');
49  $this->installerFactory->expects($this->exactly(0))->method('create');
50 
51  $this->checkInteraction(false);
52  }
53 
57  public function checkInteraction($answer)
58  {
59  $question = $this->createMock(\Symfony\Component\Console\Helper\QuestionHelper::class);
60  $question
61  ->expects($this->once())
62  ->method('ask')
63  ->will($this->returnValue($answer));
64 
66  $helperSet = $this->createMock(\Symfony\Component\Console\Helper\HelperSet::class);
67  $helperSet
68  ->expects($this->once())
69  ->method('get')
70  ->with('question')
71  ->will($this->returnValue($question));
72  $this->command->setHelperSet($helperSet);
73 
74  $tester = new CommandTester($this->command);
75  $tester->execute([]);
76  }
77 }