_stateMock = $this->createMock(\Magento\Framework\App\State::class); $this->_request = $this->createMock(\Magento\Framework\App\Console\Request::class); $this->_responseMock = $this->createMock(\Magento\Framework\App\Console\Response::class); $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class); $this->_model = new Cron( $this->_stateMock, $this->_request, $this->_responseMock, $this->objectManager, [], $this->prepareAreaListMock() ); } /** * @return \PHPUnit_Framework_MockObject_MockObject */ protected function prepareAreaListMock() { $areaMock = $this->createMock(\Magento\Framework\App\Area::class); $areaMock->expects($this->once()) ->method('load') ->with(Area::PART_TRANSLATE); $areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class); $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->createMock(\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] ])); $crontabConfig = ['config']; $configLoader->expects($this->once()) ->method('load') ->with(Area::AREA_CRONTAB) ->willReturn($crontabConfig); $this->objectManager->expects($this->once()) ->method('configure') ->with($crontabConfig); $this->_stateMock->expects($this->once())->method('setAreaCode')->with(Area::AREA_CRONTAB); $eventManagerMock->expects($this->once())->method('dispatch')->with('default'); $this->_responseMock->expects($this->once())->method('setCode')->with(0); $this->assertEquals($this->_responseMock, $this->_model->launch()); } }