Skip to content

Commit 981e511

Browse files
author
Ivan Gavryshko
committed
MAGETWO-35133: Search for Commands
- changes according to CR - added unittests
1 parent d7be6e7 commit 981e511

File tree

6 files changed

+91
-4
lines changed

6 files changed

+91
-4
lines changed

dev/tools/Magento/Tools/Console/CommandList.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Tools\Console;
88

9+
use Symfony\Component\Console\Command\Command;
10+
911
class CommandList
1012
{
1113
/**
@@ -29,7 +31,10 @@ public function getCommands()
2931

3032
foreach ($this->getCommandsClasses() as $class) {
3133
if (class_exists($class)) {
32-
$commands[] = new $class;
34+
$command = new $class;;
35+
if ($command instanceof Command) {
36+
$commands[] = $command;
37+
}
3338
}
3439
}
3540

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\Test\Unit\Console;
8+
9+
use Magento\Framework\Console\CommandList;
10+
11+
class CommandListTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Console\CommandList
15+
*/
16+
private $commandList;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface
20+
*/
21+
private $objectManager;
22+
23+
public function setUp()
24+
{
25+
$commands =[
26+
'Symfony\Component\Console\Command\Command'
27+
];
28+
29+
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false);
30+
$this->commandList = new CommandList($this->objectManager, $commands);
31+
}
32+
33+
public function testGetCommands()
34+
{
35+
$this->objectManager->expects($this->once())->method('get')->with('Symfony\Component\Console\Command\Command');
36+
$this->commandList->getCommands();
37+
}
38+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Framework\Console;
88

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

1112
class CommandList
1213
{
@@ -42,7 +43,10 @@ public function getCommands()
4243
$commands = [];
4344
foreach ($this->commands as $class) {
4445
if (class_exists($class)) {
45-
$commands[] = $this->objectManager->get($class);
46+
$command = $this->objectManager->get($class);
47+
if ($command instanceof Command) {
48+
$commands[] = $command;
49+
}
4650
}
4751
}
4852

lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function createPluginsAndRelationsNotReadableDataProvider()
116116

117117
public function testGetSupportedFormats()
118118
{
119-
$actual = DefinitionFactory::getSupportedFormats();
119+
$actual = \Magento\Framework\ObjectManager\DefinitionFactory::getSupportedFormats();
120120
$this->assertInternalType('array', $actual);
121121
foreach ($actual as $className) {
122122
$this->assertInternalType('string', $className);

setup/src/Magento/Setup/Console/CommandList.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Setup\Console;
88

99
use Zend\ServiceManager\ServiceManager;
10+
use Symfony\Component\Console\Command\Command;
1011

1112
class CommandList
1213
{
@@ -50,7 +51,10 @@ public function getCommands()
5051

5152
foreach ($this->getCommandsClasses() as $class) {
5253
if (class_exists($class)) {
53-
$commands[] = $this->serviceManager->create($class);
54+
$command = $this->serviceManager->create($class);
55+
if ($command instanceof Command) {
56+
$commands[] = $command;
57+
}
5458
}
5559
}
5660

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Test\Unit\Console;
8+
9+
use Magento\Setup\Console\CommandList;
10+
11+
class CommandListTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Console\CommandList
15+
*/
16+
private $commandList;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject|\Zend\ServiceManager\ServiceManager
20+
*/
21+
private $serviceManager;
22+
23+
public function setUp()
24+
{
25+
$this->serviceManager = $this->getMock('\Zend\ServiceManager\ServiceManager', [], [], '', false);
26+
$this->commandList = new CommandList($this->serviceManager);
27+
}
28+
29+
public function testGetCommands()
30+
{
31+
$this->serviceManager->expects($this->at(0))
32+
->method('create')
33+
->with('Magento\Setup\Console\Command\ConfigInstallCommand');
34+
$this->commandList->getCommands();
35+
}
36+
}

0 commit comments

Comments
 (0)