diff --git a/lib/internal/Magento/Framework/App/Cron.php b/lib/internal/Magento/Framework/App/Cron.php index 7fcf542e2fa37..53a6a08f03e2a 100644 --- a/lib/internal/Magento/Framework/App/Cron.php +++ b/lib/internal/Magento/Framework/App/Cron.php @@ -8,9 +8,11 @@ namespace Magento\Framework\App; use Magento\Framework\App; -use Magento\Framework\App\Area; use Magento\Framework\ObjectManagerInterface; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Cron implements \Magento\Framework\AppInterface { /** @@ -35,6 +37,11 @@ class Cron implements \Magento\Framework\AppInterface */ private $objectManager; + /** + * @var \Magento\Framework\App\AreaList + */ + private $areaList; + /** * Inject dependencies * @@ -43,19 +50,22 @@ class Cron implements \Magento\Framework\AppInterface * @param Console\Response $response * @param ObjectManagerInterface $objectManager * @param array $parameters + * @param AreaList|null $areaList */ public function __construct( State $state, Console\Request $request, Console\Response $response, ObjectManagerInterface $objectManager, - array $parameters = [] + array $parameters = [], + \Magento\Framework\App\AreaList $areaList = null ) { $this->_state = $state; $this->_request = $request; $this->_request->setParams($parameters); $this->_response = $response; $this->objectManager = $objectManager; + $this->areaList = $areaList ? $areaList : $this->objectManager->get(\Magento\Framework\App\AreaList::class); } /** @@ -69,6 +79,8 @@ public function launch() $configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class); $this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB)); + $this->areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE); + /** @var \Magento\Framework\Event\ManagerInterface $eventManager */ $eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class); $eventManager->dispatch('default'); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/CronTest.php b/lib/internal/Magento/Framework/App/Test/Unit/CronTest.php index 01ca7e972c1b8..a257b6fa297eb 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/CronTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/CronTest.php @@ -46,18 +46,42 @@ protected function setUp() $this->_request = $this->getMock(\Magento\Framework\App\Console\Request::class, [], [], '', false); $this->_responseMock = $this->getMock(\Magento\Framework\App\Console\Response::class, [], [], '', false); $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class); - $this->_model = new Cron($this->_stateMock, $this->_request, $this->_responseMock, $this->objectManager); + $this->_model = new Cron( + $this->_stateMock, + $this->_request, + $this->_responseMock, + $this->objectManager, + [], + $this->prepareAreaListMock() + ); + } + + protected function prepareAreaListMock() + { + $areaMock = $this->getMock(\Magento\Framework\App\Area::class, [], [], '', false); + $areaMock->expects($this->once()) + ->method('load') + ->with(Area::PART_TRANSLATE); + + $areaListMock = $this->getMock(\Magento\Framework\App\AreaList::class, [], [], '', false); + $areaListMock->expects($this->any()) + ->method('getArea') + ->with(Area::AREA_CRONTAB) + ->willReturn($areaMock); + + return $areaListMock; } public function testLaunchDispatchesCronEvent() { $configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class); $eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class); + $this->objectManager->expects($this->any()) ->method('get') ->will($this->returnValueMap([ [\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader], - [\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock], + [\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock] ])); $crontabConfig = ['config']; $configLoader->expects($this->once())