Skip to content

Commit 099ee76

Browse files
Use injection via optional constructor param
1 parent 9601e69 commit 099ee76

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

lib/internal/Magento/Framework/App/Cron.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ public function __construct(
5656
Console\Request $request,
5757
Console\Response $response,
5858
ObjectManagerInterface $objectManager,
59-
array $parameters = []
59+
array $parameters = [],
60+
\Magento\Framework\App\AreaList $arealist = null
6061
) {
6162
$this->_state = $state;
6263
$this->_request = $request;
6364
$this->_request->setParams($parameters);
6465
$this->_response = $response;
6566
$this->objectManager = $objectManager;
67+
$this->arealist = $arealist ?: $this->objectManager->get(\Magento\Framework\App\AreaList::class);
6668
}
6769

6870
/**
@@ -76,8 +78,7 @@ public function launch()
7678
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
7779
$this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
7880

79-
$areaList = $this->getAreaList();
80-
$areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);
81+
$this->areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);
8182

8283
/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
8384
$eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
@@ -86,19 +87,6 @@ public function launch()
8687
return $this->_response;
8788
}
8889

89-
/**
90-
* @deprecated
91-
*
92-
* @return \Magento\Framework\App\AreaList
93-
*/
94-
private function getAreaList()
95-
{
96-
if ($this->areaList === null) {
97-
$this->areaList = $this->objectManager->get(\Magento\Framework\App\AreaList::class);
98-
}
99-
return $this->areaList;
100-
}
101-
10290
/**
10391
* {@inheritdoc}
10492
*/

lib/internal/Magento/Framework/App/Test/Unit/CronTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ protected function setUp()
4646
$this->_request = $this->getMock(\Magento\Framework\App\Console\Request::class, [], [], '', false);
4747
$this->_responseMock = $this->getMock(\Magento\Framework\App\Console\Response::class, [], [], '', false);
4848
$this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
49-
$this->_model = new Cron($this->_stateMock, $this->_request, $this->_responseMock, $this->objectManager);
49+
$this->_model = new Cron(
50+
$this->_stateMock,
51+
$this->_request,
52+
$this->_responseMock,
53+
$this->objectManager,
54+
[],
55+
$this->prepareAreaListMock()
56+
);
5057
}
5158

52-
public function testLaunchDispatchesCronEvent()
59+
protected function prepareAreaListMock()
5360
{
54-
$configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
55-
$eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);
56-
5761
$areaMock = $this->getMock(\Magento\Framework\App\Area::class, [], [], '', false);
5862
$areaMock->expects($this->once())
5963
->method('load')
@@ -65,12 +69,19 @@ public function testLaunchDispatchesCronEvent()
6569
->with(Area::AREA_CRONTAB)
6670
->willReturn($areaMock);
6771

72+
return $areaListMock;
73+
}
74+
75+
public function testLaunchDispatchesCronEvent()
76+
{
77+
$configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
78+
$eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);
79+
6880
$this->objectManager->expects($this->any())
6981
->method('get')
7082
->will($this->returnValueMap([
7183
[\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader],
72-
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock],
73-
[\Magento\Framework\App\AreaList::class, $areaListMock]
84+
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock]
7485
]));
7586
$crontabConfig = ['config'];
7687
$configLoader->expects($this->once())

0 commit comments

Comments
 (0)