Skip to content

Commit 764a2c6

Browse files
committed
Implement command loader
Fix test failures
1 parent f162173 commit 764a2c6

37 files changed

+149
-183
lines changed

app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class MaintenanceAllowIpsCommand extends AbstractSetupCommand
2222
/**
2323
* Names of input arguments or options
2424
*/
25-
const INPUT_KEY_IP = 'ip';
26-
const INPUT_KEY_NONE = 'none';
27-
const INPUT_KEY_ADD = 'add';
28-
const NAME = 'maintenance:allow-ips';
25+
public const INPUT_KEY_IP = 'ip';
26+
public const INPUT_KEY_NONE = 'none';
27+
public const INPUT_KEY_ADD = 'add';
28+
public const NAME = 'maintenance:allow-ips';
2929

3030
/**
3131
* @var MaintenanceMode

app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class MaintenanceDisableCommand extends AbstractMaintenanceCommand
1212
{
13-
const NAME = 'maintenance:disable';
13+
public const NAME = 'maintenance:disable';
1414

1515
/**
1616
* Initialization of the command

app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class MaintenanceEnableCommand extends AbstractMaintenanceCommand
1212
{
13-
const NAME = 'maintenance:enable';
13+
public const NAME = 'maintenance:enable';
1414

1515
/**
1616
* Initialization of the command

app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class MaintenanceStatusCommand extends AbstractSetupCommand
1818
{
19-
const NAME = 'maintenance:status';
19+
public const NAME = 'maintenance:status';
2020

2121
/**
2222
* @var MaintenanceMode $maintenanceMode

lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
@@ -18,14 +19,14 @@
1819
*/
1920
class AggregateTest extends TestCase
2021
{
21-
/** @var MockObject */
22-
private $firstMockCommandLoader;
22+
/** @var CommandLoaderInterface|MockObject */
23+
private MockObject|CommandLoaderInterface $firstMockCommandLoader;
2324

24-
/** @var MockObject */
25-
private $secondMockCommandLoader;
25+
/** @var CommandLoaderInterface|MockObject */
26+
private MockObject|CommandLoaderInterface $secondMockCommandLoader;
2627

2728
/** @var Aggregate */
28-
private $aggregateCommandLoader;
29+
private Aggregate $aggregateCommandLoader;
2930

3031
protected function setUp(): void
3132
{
@@ -41,15 +42,15 @@ protected function setUp(): void
4142
*
4243
* @dataProvider provideTestCasesForHas
4344
*/
44-
public function testHas(bool $firstResult, bool $secondResult, bool $overallResult)
45+
public function testHas(bool $firstResult, bool $secondResult, bool $overallResult): void
4546
{
4647
$this->firstMockCommandLoader->method('has')->with('foo')->willReturn($firstResult);
4748
$this->secondMockCommandLoader->method('has')->with('foo')->willReturn($secondResult);
4849

4950
$this->assertEquals($overallResult, $this->aggregateCommandLoader->has('foo'));
5051
}
5152

52-
public function provideTestCasesForHas()
53+
public function provideTestCasesForHas(): array
5354
{
5455
return [
5556
[true, false, true],
@@ -66,7 +67,7 @@ public function provideTestCasesForHas()
6667
*
6768
* @dataProvider provideTestCasesForGet
6869
*/
69-
public function testGet(?Command $firstCmd, ?Command $secondCmd)
70+
public function testGet(?Command $firstCmd, ?Command $secondCmd): void
7071
{
7172
$firstHas = (bool)$firstCmd;
7273
$secondHas = (bool)$secondCmd;
@@ -78,7 +79,7 @@ public function testGet(?Command $firstCmd, ?Command $secondCmd)
7879
$this->assertInstanceOf(Command::class, $this->aggregateCommandLoader->get('foo'));
7980
}
8081

81-
public function provideTestCasesForGet()
82+
public function provideTestCasesForGet(): array
8283
{
8384
return [
8485
[
@@ -96,7 +97,7 @@ public function provideTestCasesForGet()
9697
* When none of the internal command loaders have matching commands, the aggregate command loader
9798
* will throw an exception. @see CommandNotFoundException
9899
*/
99-
public function testGetThrow()
100+
public function testGetThrow(): void
100101
{
101102
$this->firstMockCommandLoader->method('has')->with('foo')->willReturn(false);
102103
$this->secondMockCommandLoader->method('has')->with('foo')->willReturn(false);
@@ -109,7 +110,7 @@ public function testGetThrow()
109110
* An aggregate command loader's `getNames` method returns the merged array of the `getNames`
110111
* return values of all its internal command loaders
111112
*/
112-
public function testGetNames()
113+
public function testGetNames(): void
113114
{
114115
$this->firstMockCommandLoader->method('getNames')->willReturn(['foo', 'bar']);
115116
$this->secondMockCommandLoader->method('getNames')->willReturn(['baz', 'qux']);

lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
@@ -7,14 +8,15 @@
78

89
use Magento\Framework\Console\CommandLoader;
910
use Magento\Framework\ObjectManagerInterface;
11+
use PHPUnit\Framework\MockObject\MockObject;
1012
use PHPUnit\Framework\TestCase;
1113
use Symfony\Component\Console\Command\Command;
1214
use Symfony\Component\Console\Exception\CommandNotFoundException;
1315

1416
class CommandLoaderTest extends TestCase
1517
{
16-
/** @var \PHPUnit\Framework\MockObject\MockObject|ObjectManagerInterface */
17-
private $objectManagerMock;
18+
/** @var MockObject|ObjectManagerInterface */
19+
private ObjectManagerInterface|MockObject $objectManagerMock;
1820

1921
protected function setUp(): void
2022
{
@@ -24,7 +26,7 @@ protected function setUp(): void
2426
/**
2527
* Test that the command loader, when provided zero commands, does not have a command named "foo"
2628
*/
27-
public function testHasWithZeroCommands()
29+
public function testHasWithZeroCommands(): void
2830
{
2931
$subj = new CommandLoader($this->objectManagerMock, []);
3032

@@ -34,7 +36,7 @@ public function testHasWithZeroCommands()
3436
/**
3537
* Test that the command loader will return true when provided with a command "foo"
3638
*/
37-
public function testHasWithAtLeastOneCommand()
39+
public function testHasWithAtLeastOneCommand(): void
3840
{
3941
$subj = new CommandLoader($this->objectManagerMock, [
4042
[
@@ -49,7 +51,7 @@ public function testHasWithAtLeastOneCommand()
4951
/**
5052
* Test that the command loader will throw a CommandNotFoundException when it does not have the requested command
5153
*/
52-
public function testGetWithZeroCommands()
54+
public function testGetWithZeroCommands(): void
5355
{
5456
$subj = new CommandLoader($this->objectManagerMock, []);
5557

@@ -61,7 +63,7 @@ public function testGetWithZeroCommands()
6163
/**
6264
* Test that the command loader returns a command when one it has is requested
6365
*/
64-
public function testGetWithAtLeastOneCommand()
66+
public function testGetWithAtLeastOneCommand(): void
6567
{
6668
$this->objectManagerMock
6769
->method('create')
@@ -81,7 +83,7 @@ public function testGetWithAtLeastOneCommand()
8183
/**
8284
* Test that the command loader will return an empty "names" array when it has none
8385
*/
84-
public function testGetNamesWithZeroCommands()
86+
public function testGetNamesWithZeroCommands(): void
8587
{
8688
$subj = new CommandLoader($this->objectManagerMock, []);
8789

@@ -91,7 +93,7 @@ public function testGetNamesWithZeroCommands()
9193
/**
9294
* Test that the command loader returns an array of its command names when `getNames` is called
9395
*/
94-
public function testGetNames()
96+
public function testGetNames(): void
9597
{
9698
$subj = new CommandLoader($this->objectManagerMock, [
9799
[

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Framework\Console;
99

10+
use Laminas\ServiceManager\ServiceManager;
1011
use Magento\Framework\App\Bootstrap;
1112
use Magento\Framework\App\DeploymentConfig;
1213
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -39,16 +40,18 @@ class Cli extends Console\Application
3940
/**
4041
* Name of input option.
4142
*/
42-
const INPUT_KEY_BOOTSTRAP = 'bootstrap';
43+
public const INPUT_KEY_BOOTSTRAP = 'bootstrap';
4344

4445
/**#@+
4546
* Cli exit codes.
4647
*/
47-
const RETURN_SUCCESS = 0;
48-
const RETURN_FAILURE = 1;
48+
public const RETURN_SUCCESS = 0;
49+
public const RETURN_FAILURE = 1;
4950
/**#@-*/
5051

51-
/**#@-*/
52+
/**
53+
* @var ServiceManager
54+
*/
5255
private $serviceManager;
5356

5457
/**
@@ -59,8 +62,6 @@ class Cli extends Console\Application
5962
private $initException;
6063

6164
/**
62-
* Object Manager.
63-
*
6465
* @var ObjectManagerInterface
6566
*/
6667
private $objectManager;

lib/internal/Magento/Framework/Console/CommandLoader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Magento\Framework\Console;
1010

1111
use Magento\Framework\ObjectManagerInterface;
12+
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
1314
use Symfony\Component\Console\Exception\CommandNotFoundException;
1415

@@ -17,15 +18,14 @@
1718
*/
1819
class CommandLoader implements CommandLoaderInterface
1920
{
20-
2121
/**
2222
* List of commands in the format [ 'command:name' => 'Fully\Qualified\ClassName' ]
2323
* @var array
2424
*/
25-
private $commands;
25+
private array $commands;
2626

2727
/** @var ObjectManagerInterface */
28-
private $objectManager;
28+
private ObjectManagerInterface $objectManager;
2929

3030
/**
3131
* @param ObjectManagerInterface $objectManager
@@ -43,10 +43,10 @@ public function __construct(ObjectManagerInterface $objectManager, array $comman
4343
* If the command name is not configured, throw a CommandNotFoundException.
4444
*
4545
* @param string $name
46-
* @return \Symfony\Component\Console\Command\Command
46+
* @return Command
4747
* @throws CommandNotFoundException
4848
*/
49-
public function get($name): \Symfony\Component\Console\Command\Command
49+
public function get(string $name): Command
5050
{
5151
if ($this->has($name)) {
5252
return $this->objectManager->create($this->commands[$name]);
@@ -60,7 +60,7 @@ public function get($name): \Symfony\Component\Console\Command\Command
6060
* @param string $name
6161
* @return bool
6262
*/
63-
public function has($name): bool
63+
public function has(string $name): bool
6464
{
6565
return isset($this->commands[$name]);
6666
}

lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Framework\Console\CommandLoader;
1010

11+
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
1213
use Symfony\Component\Console\Exception\CommandNotFoundException;
1314

@@ -17,7 +18,7 @@
1718
class Aggregate implements CommandLoaderInterface
1819
{
1920
/** @var CommandLoaderInterface[] */
20-
private $commandLoaders;
21+
private array $commandLoaders;
2122

2223
/**
2324
* @param array $commandLoaders
@@ -33,10 +34,10 @@ public function __construct(array $commandLoaders = [])
3334
* If $name does not refer to a command, throw a CommandNotFoundException.
3435
*
3536
* @param string $name
36-
* @return \Symfony\Component\Console\Command\Command
37+
* @return Command
3738
* @throws CommandNotFoundException
3839
*/
39-
public function get($name): \Symfony\Component\Console\Command\Command
40+
public function get(string $name): Command
4041
{
4142
foreach ($this->commandLoaders as $commandLoader) {
4243
if ($commandLoader->has($name)) {
@@ -53,7 +54,7 @@ public function get($name): \Symfony\Component\Console\Command\Command
5354
* @param string $name
5455
* @return bool
5556
*/
56-
public function has($name): bool
57+
public function has(string $name): bool
5758
{
5859
foreach ($this->commandLoaders as $commandLoader) {
5960
if ($commandLoader->has($name)) {
@@ -71,7 +72,7 @@ public function has($name): bool
7172
*/
7273
public function getNames(): array
7374
{
74-
return array_merge([], ...array_map(function (CommandLoaderInterface $commandLoader) {
75+
return array_merge([], ...array_map(static function (CommandLoaderInterface $commandLoader) {
7576
return $commandLoader->getNames();
7677
}, $this->commandLoaders));
7778
}

setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class AdminUserCreateCommand extends AbstractSetupCommand
2323
{
24-
const NAME = 'admin:user:create';
24+
public const NAME = 'admin:user:create';
2525
/**
2626
* @var InstallerFactory
2727
*/

0 commit comments

Comments
 (0)