objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class) ->getMock(); $this->settlementFactoryMock = $this->getMockBuilder(\Magento\Paypal\Model\Report\SettlementFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $this->logger = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class); $this->objectManager = new ObjectManager($this); $this->fetchReports = $this->objectManager->getObject( \Magento\Paypal\Cron\FetchReports::class, [ 'settlementFactory' => $this->settlementFactoryMock ] ); } /** * @expectedException \Exception */ public function testExecuteThrowsException() { $sftpCredentials = [ 'hostname' => ['test_hostname'], 'username' => ['test_username'], 'password' => ['test_password'], 'path' => ['test_path'] ]; $settlementMock = $this->getMockBuilder(\Magento\Paypal\Model\Report\Settlement::class) ->disableOriginalConstructor() ->getMock(); $this->settlementFactoryMock->expects($this->once()) ->method('create') ->willReturn($settlementMock); $settlementMock->expects($this->once())->method('getSftpCredentials')->with(true)->willReturn($sftpCredentials); $settlementMock->expects($this->any())->method('fetchAndSave')->willThrowException(new \Exception); $this->logger->expects($this->never())->method('critical'); $this->fetchReports->execute(); } }