Skip to content

Commit b3e0344

Browse files
committed
Merge remote-tracking branch 'mpi/MC-19749' into Chaika-2019-09-12-CE
2 parents 4602182 + 17f291b commit b3e0344

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

dev/tests/integration/testsuite/Magento/Setup/Model/ObjectManagerProviderTest.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,52 @@
66

77
namespace Magento\Setup\Model;
88

9+
use Magento\Framework\ObjectManagerInterface;
910
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
11+
use PHPUnit\Framework\TestCase;
12+
use PHPUnit_Framework_MockObject_MockObject;
13+
use Symfony\Component\Console\Application;
14+
use Zend\ServiceManager\ServiceLocatorInterface;
1015

11-
class ObjectManagerProviderTest extends \PHPUnit\Framework\TestCase
16+
/**
17+
* Tests ObjectManagerProvider
18+
*/
19+
class ObjectManagerProviderTest extends TestCase
1220
{
1321
/**
1422
* @var ObjectManagerProvider
1523
*/
1624
private $object;
1725

1826
/**
19-
* @var \Zend\ServiceManager\ServiceLocatorInterface|\PHPUnit_Framework_MockObject_MockObject
27+
* @var ServiceLocatorInterface|PHPUnit_Framework_MockObject_MockObject
2028
*/
2129
private $locator;
2230

31+
/**
32+
* @inheritDoc
33+
*/
2334
protected function setUp()
2435
{
25-
$this->locator = $this->getMockForAbstractClass(\Zend\ServiceManager\ServiceLocatorInterface::class);
36+
$this->locator = $this->getMockForAbstractClass(ServiceLocatorInterface::class);
2637
$this->object = new ObjectManagerProvider($this->locator, new Bootstrap());
38+
$this->locator->expects($this->any())
39+
->method('get')
40+
->willReturnMap(
41+
[
42+
[InitParamListener::BOOTSTRAP_PARAM, []],
43+
[Application::class, $this->getMockForAbstractClass(Application::class)],
44+
]
45+
);
2746
}
2847

48+
/**
49+
* Tests the same instance of ObjectManagerInterface should be provided by the ObjectManagerProvider
50+
*/
2951
public function testGet()
3052
{
31-
$this->locator->expects($this->once())->method('get')->with(InitParamListener::BOOTSTRAP_PARAM)->willReturn([]);
3253
$objectManager = $this->object->get();
33-
$this->assertInstanceOf(\Magento\Framework\ObjectManagerInterface::class, $objectManager);
54+
$this->assertInstanceOf(ObjectManagerInterface::class, $objectManager);
3455
$this->assertSame($objectManager, $this->object->get());
3556
}
3657
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
9393
}
9494

9595
parent::__construct($name, $version);
96+
$this->serviceManager->setService(\Symfony\Component\Console\Application::class, $this);
9697
}
9798

9899
/**

setup/src/Magento/Setup/Model/ObjectManagerProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ private function createCliCommands()
7676
{
7777
/** @var CommandListInterface $commandList */
7878
$commandList = $this->objectManager->create(CommandListInterface::class);
79+
$application = $this->serviceLocator->get(Application::class);
7980
foreach ($commandList->getCommands() as $command) {
80-
$command->setApplication(
81-
$this->serviceLocator->get(Application::class)
82-
);
81+
$application->add($command);
8382
}
8483
}
8584

setup/src/Magento/Setup/Test/Unit/Model/ObjectManagerProviderTest.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function setUp()
4747
public function testGet()
4848
{
4949
$initParams = ['param' => 'value'];
50+
$commands = [
51+
new Command('setup:install'),
52+
new Command('setup:upgrade'),
53+
];
54+
55+
$application = $this->getMockBuilder(Application::class)
56+
->disableOriginalConstructor()
57+
->getMockForAbstractClass();
5058

5159
$this->serviceLocatorMock
5260
->expects($this->atLeastOnce())
@@ -56,16 +64,21 @@ public function testGet()
5664
[InitParamListener::BOOTSTRAP_PARAM, $initParams],
5765
[
5866
Application::class,
59-
$this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(),
67+
$application,
6068
],
6169
]
6270
);
6371

72+
$commandListMock = $this->createMock(CommandListInterface::class);
73+
$commandListMock->expects($this->once())
74+
->method('getCommands')
75+
->willReturn($commands);
76+
6477
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
6578
$objectManagerMock->expects($this->once())
6679
->method('create')
6780
->with(CommandListInterface::class)
68-
->willReturn($this->getCommandListMock());
81+
->willReturn($commandListMock);
6982

7083
$objectManagerFactoryMock = $this->getMockBuilder(ObjectManagerFactory::class)
7184
->disableOriginalConstructor()
@@ -81,21 +94,9 @@ public function testGet()
8194
->willReturn($objectManagerFactoryMock);
8295

8396
$this->assertInstanceOf(ObjectManagerInterface::class, $this->model->get());
84-
}
85-
86-
/**
87-
* @return \PHPUnit_Framework_MockObject_MockObject
88-
*/
89-
private function getCommandListMock()
90-
{
91-
$commandMock = $this->getMockBuilder(Command::class)->disableOriginalConstructor()->getMock();
92-
$commandMock->expects($this->once())->method('setApplication');
93-
94-
$commandListMock = $this->createMock(CommandListInterface::class);
95-
$commandListMock->expects($this->once())
96-
->method('getCommands')
97-
->willReturn([$commandMock]);
9897

99-
return $commandListMock;
98+
foreach ($commands as $command) {
99+
$this->assertSame($application, $command->getApplication());
100+
}
100101
}
101102
}

0 commit comments

Comments
 (0)