Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FetchReportsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class FetchReportsTest extends \PHPUnit\Framework\TestCase
11 {
15  private $objectManager;
16 
20  private $fetchReports;
21 
25  private $settlementFactoryMock;
26 
30  private $objectManagerMock;
31 
35  private $logger;
36 
37  protected function setUp()
38  {
39  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
40  ->getMock();
41  $this->settlementFactoryMock = $this->getMockBuilder(\Magento\Paypal\Model\Report\SettlementFactory::class)
42  ->disableOriginalConstructor()
43  ->setMethods(['create'])
44  ->getMock();
45  $this->logger = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);
46 
47  $this->objectManager = new ObjectManager($this);
48  $this->fetchReports = $this->objectManager->getObject(
49  \Magento\Paypal\Cron\FetchReports::class,
50  [
51  'settlementFactory' => $this->settlementFactoryMock
52  ]
53  );
54  }
55 
59  public function testExecuteThrowsException()
60  {
61  $sftpCredentials = [
62  'hostname' => ['test_hostname'],
63  'username' => ['test_username'],
64  'password' => ['test_password'],
65  'path' => ['test_path']
66  ];
67  $settlementMock = $this->getMockBuilder(\Magento\Paypal\Model\Report\Settlement::class)
68  ->disableOriginalConstructor()
69  ->getMock();
70 
71  $this->settlementFactoryMock->expects($this->once())
72  ->method('create')
73  ->willReturn($settlementMock);
74 
75  $settlementMock->expects($this->once())->method('getSftpCredentials')->with(true)->willReturn($sftpCredentials);
76  $settlementMock->expects($this->any())->method('fetchAndSave')->willThrowException(new \Exception);
77  $this->logger->expects($this->never())->method('critical');
78 
79  $this->fetchReports->execute();
80  }
81 }