Skip to content

Commit 7e8e2d3

Browse files
committed
#27500 Migrate PHPUnit tests for module
1 parent aa20655 commit 7e8e2d3

File tree

262 files changed

+4070
-2975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+4070
-2975
lines changed

setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
@@ -7,36 +7,41 @@
77

88
use Magento\Setup\Console\Command\AdminUserCreateCommand;
99
use Magento\Setup\Model\AdminAccount;
10+
use Magento\Setup\Model\Installer;
11+
use Magento\Setup\Model\InstallerFactory;
1012
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
1113
use Magento\User\Model\UserValidationRules;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1216
use Symfony\Component\Console\Application;
1317
use Symfony\Component\Console\Helper\QuestionHelper;
18+
use Symfony\Component\Console\Input\InputInterface;
1419
use Symfony\Component\Console\Input\InputOption;
1520
use Symfony\Component\Console\Tester\CommandTester;
1621

1722
/**
1823
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1924
*/
20-
class AdminUserCreateCommandTest extends \PHPUnit\Framework\TestCase
25+
class AdminUserCreateCommandTest extends TestCase
2126
{
2227
/**
23-
* @var \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Console\Helper\QuestionHelper
28+
* @var MockObject|QuestionHelper
2429
*/
2530
private $questionHelperMock;
2631

2732
/**
28-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\InstallerFactory
33+
* @var MockObject|InstallerFactory
2934
*/
3035
private $installerFactoryMock;
3136

3237
/**
33-
* @var \PHPUnit_Framework_MockObject_MockObject|AdminUserCreateCommand
38+
* @var MockObject|AdminUserCreateCommand
3439
*/
3540
private $command;
3641

37-
public function setUp()
42+
public function setUp(): void
3843
{
39-
$this->installerFactoryMock = $this->createMock(\Magento\Setup\Model\InstallerFactory::class);
44+
$this->installerFactoryMock = $this->createMock(InstallerFactory::class);
4045
$this->command = new AdminUserCreateCommand($this->installerFactoryMock, new UserValidationRules());
4146

4247
$this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class)
@@ -62,7 +67,7 @@ public function testExecute()
6267
InitParamListener::BOOTSTRAP_PARAM => null,
6368
];
6469
$commandTester = new CommandTester($this->command);
65-
$installerMock = $this->createMock(\Magento\Setup\Model\Installer::class);
70+
$installerMock = $this->createMock(Installer::class);
6671
$installerMock->expects($this->once())->method('installAdminUser')->with($data);
6772
$this->installerFactoryMock->expects($this->once())->method('create')->willReturn($installerMock);
6873
$commandTester->execute($options, ['interactive' => false]);
@@ -97,7 +102,7 @@ public function testInteraction()
97102
// We override the standard helper with our mock
98103
$this->command->getHelperSet()->set($this->questionHelperMock, 'question');
99104

100-
$installerMock = $this->createMock(\Magento\Setup\Model\Installer::class);
105+
$installerMock = $this->createMock(Installer::class);
101106

102107
$expectedData = [
103108
'admin-user' => 'admin',
@@ -167,7 +172,7 @@ public function getOptionListDataProvider()
167172
public function testValidate(array $options, array $errors)
168173
{
169174
$inputMock = $this->getMockForAbstractClass(
170-
\Symfony\Component\Console\Input\InputInterface::class,
175+
InputInterface::class,
171176
[],
172177
'',
173178
false

setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Setup\Test\Unit\Console\Command;
77

88
use Magento\Framework\App\Console\MaintenanceModeEnabler;
9+
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\MaintenanceMode;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Framework\Setup\BackupRollback;
15+
use Magento\Framework\Setup\BackupRollbackFactory;
916
use Magento\Setup\Console\Command\BackupCommand;
17+
use Magento\Setup\Model\ObjectManagerProvider;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
1020
use Symfony\Component\Console\Tester\CommandTester;
1121

12-
class BackupCommandTest extends \PHPUnit\Framework\TestCase
22+
class BackupCommandTest extends TestCase
1323
{
1424
/**
15-
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
25+
* @var ObjectManagerInterface|MockObject
1626
*/
1727
private $objectManager;
1828

1929
/**
20-
* @var \Magento\Framework\Setup\BackupRollback|\PHPUnit_Framework_MockObject_MockObject
30+
* @var BackupRollback|MockObject
2131
*/
2232
private $backupRollback;
2333

@@ -27,35 +37,35 @@ class BackupCommandTest extends \PHPUnit\Framework\TestCase
2737
private $tester;
2838

2939
/**
30-
* @var \Magento\Framework\Setup\BackupRollbackFactory|\PHPUnit_Framework_MockObject_MockObject
40+
* @var BackupRollbackFactory|MockObject
3141
*/
3242
private $backupRollbackFactory;
3343

3444
/**
35-
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
45+
* @var DeploymentConfig|MockObject
3646
*/
3747
private $deploymentConfig;
3848

39-
public function setUp()
49+
public function setUp(): void
4050
{
41-
$maintenanceMode = $this->createMock(\Magento\Framework\App\MaintenanceMode::class);
42-
$objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
51+
$maintenanceMode = $this->createMock(MaintenanceMode::class);
52+
$objectManagerProvider = $this->createMock(ObjectManagerProvider::class);
4353
$this->objectManager = $this->getMockForAbstractClass(
44-
\Magento\Framework\ObjectManagerInterface::class,
54+
ObjectManagerInterface::class,
4555
[],
4656
'',
4757
false
4858
);
4959
$objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
50-
$this->backupRollback = $this->createMock(\Magento\Framework\Setup\BackupRollback::class);
51-
$this->backupRollbackFactory = $this->createMock(\Magento\Framework\Setup\BackupRollbackFactory::class);
60+
$this->backupRollback = $this->createMock(BackupRollback::class);
61+
$this->backupRollbackFactory = $this->createMock(BackupRollbackFactory::class);
5262
$this->backupRollbackFactory->expects($this->any())
5363
->method('create')
5464
->willReturn($this->backupRollback);
55-
$this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
56-
$appState = $this->createMock(\Magento\Framework\App\State::class);
65+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
66+
$appState = $this->createMock(State::class);
5767
$configLoader = $this->getMockForAbstractClass(
58-
\Magento\Framework\ObjectManager\ConfigLoaderInterface::class,
68+
ConfigLoaderInterface::class,
5969
[],
6070
'',
6171
false
@@ -66,9 +76,9 @@ public function setUp()
6676
->method('get')
6777
->will(
6878
$this->returnValueMap([
69-
[\Magento\Framework\Setup\BackupRollbackFactory::class, $this->backupRollbackFactory],
70-
[\Magento\Framework\App\State::class, $appState],
71-
[\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader],
79+
[BackupRollbackFactory::class, $this->backupRollbackFactory],
80+
[State::class, $appState],
81+
[ConfigLoaderInterface::class, $configLoader],
7282
])
7383
);
7484
$command = new BackupCommand(

setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

77
namespace Magento\Setup\Test\Unit\Console\Command;
88

9+
use Magento\Framework\App\DeploymentConfig;
910
use Magento\Framework\Module\ModuleList;
11+
use Magento\Framework\Setup\Option\TextConfigOption;
1012
use Magento\Setup\Console\Command\ConfigSetCommand;
13+
use Magento\Setup\Model\ConfigModel;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Console\Helper\HelperSet;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
1118
use Symfony\Component\Console\Tester\CommandTester;
1219

13-
class ConfigSetCommandTest extends \PHPUnit\Framework\TestCase
20+
class ConfigSetCommandTest extends TestCase
1421
{
1522
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConfigModel
23+
* @var MockObject|ConfigModel
1724
*/
1825
private $configModel;
1926

2027
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig
28+
* @var MockObject|DeploymentConfig
2229
*/
2330
private $deploymentConfig;
2431

2532
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Console\Command\ConfigSetCommand
33+
* @var MockObject|ConfigSetCommand
2734
*/
2835
private $command;
2936

30-
public function setUp()
37+
public function setUp(): void
3138
{
32-
$option = $this->createMock(\Magento\Framework\Setup\Option\TextConfigOption::class);
39+
$option = $this->createMock(TextConfigOption::class);
3340
$option
3441
->expects($this->any())
3542
->method('getName')
3643
->will($this->returnValue('db-host'));
37-
$this->configModel = $this->createMock(\Magento\Setup\Model\ConfigModel::class);
44+
$this->configModel = $this->createMock(ConfigModel::class);
3845
$this->configModel
3946
->expects($this->exactly(2))
4047
->method('getAvailableOptions')
4148
->will($this->returnValue([$option]));
42-
$moduleList = $this->createMock(\Magento\Framework\Module\ModuleList::class);
43-
$this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
49+
$moduleList = $this->createMock(ModuleList::class);
50+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
4451
$this->command = new ConfigSetCommand($this->configModel, $moduleList, $this->deploymentConfig);
4552
}
4653

@@ -96,14 +103,14 @@ public function testExecuteInteractiveWithNo()
96103
*/
97104
private function checkInteraction($interactionType)
98105
{
99-
$dialog = $this->createMock(\Symfony\Component\Console\Helper\QuestionHelper::class);
106+
$dialog = $this->createMock(QuestionHelper::class);
100107
$dialog
101108
->expects($this->once())
102109
->method('ask')
103110
->will($this->returnValue($interactionType));
104111

105-
/** @var \Symfony\Component\Console\Helper\HelperSet|\PHPUnit_Framework_MockObject_MockObject $helperSet */
106-
$helperSet = $this->createMock(\Symfony\Component\Console\Helper\HelperSet::class);
112+
/** @var HelperSet|MockObject $helperSet */
113+
$helperSet = $this->createMock(HelperSet::class);
107114
$helperSet
108115
->expects($this->once())
109116
->method('get')
@@ -116,7 +123,7 @@ private function checkInteraction($interactionType)
116123
if (strtolower($interactionType) === 'y') {
117124
$message = 'You saved the new configuration.' . PHP_EOL;
118125
} else {
119-
$message = 'You made no changes to the configuration.'.PHP_EOL;
126+
$message = 'You made no changes to the configuration.' . PHP_EOL;
120127
}
121128
$this->assertSame(
122129
$message,

setup/src/Magento/Setup/Test/Unit/Console/Command/CronRunCommandTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
@@ -7,12 +7,18 @@
77

88
use Magento\Framework\App\DeploymentConfig;
99
use Magento\Setup\Console\Command\CronRunCommand;
10+
use Magento\Setup\Model\Cron\AbstractJob;
11+
use Magento\Setup\Model\Cron\Queue;
12+
use Magento\Setup\Model\Cron\ReadinessCheck;
13+
use Magento\Setup\Model\Cron\Status;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1016
use Symfony\Component\Console\Tester\CommandTester;
1117

12-
class CronRunCommandTest extends \PHPUnit\Framework\TestCase
18+
class CronRunCommandTest extends TestCase
1319
{
1420
/**
15-
* @var \PHPUnit_Framework_MockObject_MockObject|DeploymentConfig
21+
* @var MockObject|DeploymentConfig
1622
*/
1723
private $deploymentConfig;
1824

@@ -27,26 +33,26 @@ class CronRunCommandTest extends \PHPUnit\Framework\TestCase
2733
private $commandTester;
2834

2935
/**
30-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Cron\Queue
36+
* @var MockObject|Queue
3137
*/
3238
private $queue;
3339

3440
/**
35-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Cron\ReadinessCheck
41+
* @var MockObject|ReadinessCheck
3642
*/
3743
private $readinessCheck;
3844

3945
/**
40-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Cron\Status
46+
* @var MockObject|Status
4147
*/
4248
private $status;
4349

44-
public function setUp()
50+
public function setUp(): void
4551
{
46-
$this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
47-
$this->queue = $this->createMock(\Magento\Setup\Model\Cron\Queue::class);
48-
$this->readinessCheck = $this->createMock(\Magento\Setup\Model\Cron\ReadinessCheck::class);
49-
$this->status = $this->createMock(\Magento\Setup\Model\Cron\Status::class);
52+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
53+
$this->queue = $this->createMock(Queue::class);
54+
$this->readinessCheck = $this->createMock(ReadinessCheck::class);
55+
$this->status = $this->createMock(Status::class);
5056
$this->command = new CronRunCommand(
5157
$this->deploymentConfig,
5258
$this->queue,
@@ -150,7 +156,7 @@ public function testExecuteJobFailed()
150156
$this->setUpPreliminarySuccess();
151157
$this->queue->expects($this->at(0))->method('peek')->willReturn(['name' => 'setup:']);
152158
$this->queue->expects($this->at(1))->method('peek')->willReturn(['name' => 'setup:']);
153-
$job = $this->getMockForAbstractClass(\Magento\Setup\Model\Cron\AbstractJob::class, [], '', false);
159+
$job = $this->getMockForAbstractClass(AbstractJob::class, [], '', false);
154160
$job->expects($this->once())->method('execute')->willThrowException(new \Exception('job failed'));
155161
$this->queue->expects($this->at(2))->method('popQueuedJob')->willReturn($job);
156162
$this->status->expects($this->atLeastOnce())->method('toggleUpdateError')->with(true);
@@ -162,7 +168,7 @@ public function testExecute()
162168
$this->setUpPreliminarySuccess();
163169
$this->queue->expects($this->at(0))->method('peek')->willReturn(['name' => 'setup:']);
164170
$this->queue->expects($this->at(1))->method('peek')->willReturn(['name' => 'setup:']);
165-
$job = $this->getMockForAbstractClass(\Magento\Setup\Model\Cron\AbstractJob::class, [], '', false);
171+
$job = $this->getMockForAbstractClass(AbstractJob::class, [], '', false);
166172
$job->expects($this->once())->method('execute');
167173
$this->queue->expects($this->at(2))->method('popQueuedJob')->willReturn($job);
168174
$this->status->expects($this->never())->method('toggleUpdateError')->with(true);

0 commit comments

Comments
 (0)