Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpgradeCommandTest.php
Go to the documentation of this file.
1 <?php
7 
14 use Symfony\Component\Console\Tester\CommandTester;
15 
16 class UpgradeCommandTest extends \PHPUnit\Framework\TestCase
17 {
21  private $deploymentConfigMock;
22 
26  private $installerFactoryMock;
27 
31  private $installerMock;
32 
36  private $appStateMock;
37 
41  private $upgradeCommand;
45  private $commandTester;
46 
50  protected function setUp()
51  {
52  $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->installerFactoryMock = $this->getMockBuilder(InstallerFactory::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->installerMock = $this->getMockBuilder(Installer::class)
59  ->disableOriginalConstructor()
60  ->getMock();
61  $this->installerFactoryMock->expects($this->once())
62  ->method('create')
63  ->willReturn($this->installerMock);
64  $this->appStateMock = $this->getMockBuilder(AppState::class)
65  ->disableOriginalConstructor()
66  ->getMock();
67 
68  $this->upgradeCommand = new UpgradeCommand(
69  $this->installerFactoryMock,
70  $this->deploymentConfigMock,
71  $this->appStateMock
72  );
73  $this->commandTester = new CommandTester($this->upgradeCommand);
74  }
75 
83  public function testExecute($options, $deployMode, $expectedString, $expectedOptions)
84  {
85  $this->appStateMock->method('getMode')->willReturn($deployMode);
86  $this->installerMock->expects($this->at(0))
87  ->method('updateModulesSequence');
88  $this->installerMock->expects($this->once())
89  ->method('installSchema')
90  ->with($expectedOptions);
91  $this->installerMock->expects($this->at(2))
92  ->method('installDataFixtures');
93 
94  $this->assertSame(Cli::RETURN_SUCCESS, $this->commandTester->execute($options));
95  $this->assertEquals($expectedString, $this->commandTester->getDisplay());
96  }
97 
101  public function executeDataProvider()
102  {
103  return [
104  [
105  'options' => [
106  '--magento-init-params' => '',
107  '--convert-old-scripts' => false,
108  ],
110  'expectedString' => 'Please re-run Magento compile command. Use the command "setup:di:compile"'
111  . PHP_EOL,
112  'expectedOptions' => [
113  'keep-generated' => false,
114  'convert-old-scripts' => false,
115  'safe-mode' => false,
116  'data-restore' => false,
117  'dry-run' => false,
118  'magento-init-params' => '',
119  ]
120  ],
121  [
122  'options' => [
123  '--magento-init-params' => '',
124  '--convert-old-scripts' => false,
125  '--keep-generated' => true,
126  ],
128  'expectedString' => '',
129  'expectedOptions' => [
130  'keep-generated' => true,
131  'convert-old-scripts' => false,
132  'safe-mode' => false,
133  'data-restore' => false,
134  'dry-run' => false,
135  'magento-init-params' => '',
136  ]
137  ],
138  [
139  'options' => ['--magento-init-params' => '', '--convert-old-scripts' => false],
141  'expectedString' => '',
142  'expectedOptions' => [
143  'keep-generated' => false,
144  'convert-old-scripts' => false,
145  'safe-mode' => false,
146  'data-restore' => false,
147  'dry-run' => false,
148  'magento-init-params' => '',
149  ]
150  ],
151  [
152  'options' => ['--magento-init-params' => '', '--convert-old-scripts' => false],
154  'expectedString' => '',
155  'expectedOptions' => [
156  'keep-generated' => false,
157  'convert-old-scripts' => false,
158  'safe-mode' => false,
159  'data-restore' => false,
160  'dry-run' => false,
161  'magento-init-params' => '',
162  ]
163  ],
164  ];
165  }
166 }
testExecute($options, $deployMode, $expectedString, $expectedOptions)