Skip to content

Commit d5742ed

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'origin/MAGETWO-64379-PR-8413' into develop-prs
2 parents 1fcc7f3 + dbcac67 commit d5742ed

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\Framework\App;
99

1010
use Magento\Framework\App;
11-
use Magento\Framework\App\Area;
1211
use Magento\Framework\ObjectManagerInterface;
1312

13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1416
class Cron implements \Magento\Framework\AppInterface
1517
{
1618
/**
@@ -35,6 +37,11 @@ class Cron implements \Magento\Framework\AppInterface
3537
*/
3638
private $objectManager;
3739

40+
/**
41+
* @var \Magento\Framework\App\AreaList
42+
*/
43+
private $areaList;
44+
3845
/**
3946
* Inject dependencies
4047
*
@@ -43,19 +50,22 @@ class Cron implements \Magento\Framework\AppInterface
4350
* @param Console\Response $response
4451
* @param ObjectManagerInterface $objectManager
4552
* @param array $parameters
53+
* @param AreaList|null $areaList
4654
*/
4755
public function __construct(
4856
State $state,
4957
Console\Request $request,
5058
Console\Response $response,
5159
ObjectManagerInterface $objectManager,
52-
array $parameters = []
60+
array $parameters = [],
61+
\Magento\Framework\App\AreaList $areaList = null
5362
) {
5463
$this->_state = $state;
5564
$this->_request = $request;
5665
$this->_request->setParams($parameters);
5766
$this->_response = $response;
5867
$this->objectManager = $objectManager;
68+
$this->areaList = $areaList ? $areaList : $this->objectManager->get(\Magento\Framework\App\AreaList::class);
5969
}
6070

6171
/**
@@ -69,6 +79,8 @@ public function launch()
6979
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
7080
$this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
7181

82+
$this->areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);
83+
7284
/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
7385
$eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
7486
$eventManager->dispatch('default');

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,42 @@ 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+
);
57+
}
58+
59+
protected function prepareAreaListMock()
60+
{
61+
$areaMock = $this->getMock(\Magento\Framework\App\Area::class, [], [], '', false);
62+
$areaMock->expects($this->once())
63+
->method('load')
64+
->with(Area::PART_TRANSLATE);
65+
66+
$areaListMock = $this->getMock(\Magento\Framework\App\AreaList::class, [], [], '', false);
67+
$areaListMock->expects($this->any())
68+
->method('getArea')
69+
->with(Area::AREA_CRONTAB)
70+
->willReturn($areaMock);
71+
72+
return $areaListMock;
5073
}
5174

5275
public function testLaunchDispatchesCronEvent()
5376
{
5477
$configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
5578
$eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);
79+
5680
$this->objectManager->expects($this->any())
5781
->method('get')
5882
->will($this->returnValueMap([
5983
[\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader],
60-
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock],
84+
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock]
6185
]));
6286
$crontabConfig = ['config'];
6387
$configLoader->expects($this->once())

0 commit comments

Comments
 (0)