Skip to content

Commit 11ebbe1

Browse files
author
Ivan Gavryshko
committed
MAGETWO-35133: Search for Commands
- optimized Framework CommandList, it does not require object manager now.
1 parent 9c93a1e commit 11ebbe1

File tree

2 files changed

+12
-40
lines changed

2 files changed

+12
-40
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Framework\App\Test\Unit\Console;
88

99
use Magento\Framework\Console\CommandList;
10+
use Symfony\Component\Console\Command\Command;
1011

1112
class CommandListTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -16,36 +17,24 @@ class CommandListTest extends \PHPUnit_Framework_TestCase
1617
private $commandList;
1718

1819
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface
20+
* @var Symfony\Component\Console\Command\Command
2021
*/
21-
private $objectManager;
22+
private $testCommand;
2223

2324
public function setUp()
2425
{
25-
$commands =[
26-
'Symfony\Component\Console\Command\Command'
26+
$this->testCommand = new Command('Test');
27+
$commands = [
28+
$this->testCommand
2729
];
2830

29-
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false);
30-
$this->commandList = new CommandList($this->objectManager, $commands);
31+
$this->commandList = new CommandList($commands);
3132
}
3233

3334
public function testGetCommands()
3435
{
35-
$this->objectManager->expects($this->once())->method('get')->with('Symfony\Component\Console\Command\Command');
36-
$this->commandList->getCommands();
37-
}
38-
39-
/**
40-
* @expectedException \Exception
41-
* @expectedExceptionMessage Class Symfony\Component\Console\Command\WrongCommand does not exist
42-
*/
43-
public function testGetCommandsException()
44-
{
45-
$wrongCommands =[
46-
'Symfony\Component\Console\Command\WrongCommand'
47-
];
48-
$commandList = new CommandList($this->objectManager, $wrongCommands);
49-
$commandList->getCommands();
36+
$commands = $this->commandList->getCommands();
37+
$this->assertEquals(1, count($commands));
38+
$this->assertEquals($this->testCommand, $commands[0]);
5039
}
5140
}

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,23 @@ class CommandList
2020
*/
2121
protected $commands;
2222

23-
/**
24-
* @var ObjectManagerInterface
25-
*/
26-
protected $objectManager;
27-
2823
/**
2924
* Constructor
3025
*
31-
* @param ObjectManagerInterface $objectManager
3226
* @param array $commands
3327
*/
34-
public function __construct(ObjectManagerInterface $objectManager, array $commands = [])
28+
public function __construct(array $commands = [])
3529
{
36-
$this->objectManager = $objectManager;
3730
$this->commands = $commands;
3831
}
3932

4033
/**
4134
* Gets list of command instances
4235
*
4336
* @return \Symfony\Component\Console\Command\Command[]
44-
* @throws \Exception
4537
*/
4638
public function getCommands()
4739
{
48-
$commands = [];
49-
foreach ($this->commands as $class) {
50-
if (class_exists($class)) {
51-
$commands[] = $this->objectManager->get($class);
52-
} else {
53-
throw new \Exception('Class ' . $class . ' does not exist');
54-
}
55-
}
56-
57-
return $commands;
40+
return $this->commands;
5841
}
5942
}

0 commit comments

Comments
 (0)