Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BackupFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class BackupFactoryTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_instance;
14 
18  protected $_objectManager;
19 
23  protected $_fsCollection;
24 
28  protected $_backupModel;
29 
33  protected $_data;
34 
35  protected function setUp()
36  {
37  $this->_data = [
38  'id' => '1385661590_snapshot',
39  'time' => 1385661590,
40  'path' => 'C:\test\test\var\backups',
41  'name' => '',
42  'type' => 'snapshot',
43  ];
44  $this->_fsCollection = $this->createMock(\Magento\Backup\Model\Fs\Collection::class);
45  $this->_fsCollection->expects(
46  $this->at(0)
47  )->method(
48  'getIterator'
49  )->will(
50  $this->returnValue(new \ArrayIterator([new \Magento\Framework\DataObject($this->_data)]))
51  );
52 
53  $this->_backupModel = $this->createMock(\Magento\Backup\Model\Backup::class);
54 
55  $this->_objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
56  $this->_objectManager->expects(
57  $this->at(0)
58  )->method(
59  'create'
60  )->with(
61  \Magento\Backup\Model\Fs\Collection::class
62  )->will(
63  $this->returnValue($this->_fsCollection)
64  );
65  $this->_objectManager->expects(
66  $this->at(1)
67  )->method(
68  'create'
69  )->with(
70  \Magento\Backup\Model\Backup::class
71  )->will(
72  $this->returnValue($this->_backupModel)
73  );
74 
75  $this->_instance = new \Magento\Backup\Model\BackupFactory($this->_objectManager);
76  }
77 
78  public function testCreate()
79  {
80  $this->_backupModel->expects($this->once())
81  ->method('setType')
82  ->with($this->_data['type'])
83  ->will($this->returnSelf());
84 
85  $this->_backupModel->expects($this->once())
86  ->method('setTime')
87  ->with($this->_data['time'])
88  ->will($this->returnSelf());
89 
90  $this->_backupModel->expects($this->once())
91  ->method('setName')
92  ->with($this->_data['name'])
93  ->will($this->returnSelf());
94 
95  $this->_backupModel->expects($this->once())
96  ->method('setPath')
97  ->with($this->_data['path'])
98  ->will($this->returnSelf());
99 
100  $this->_backupModel->expects($this->once())
101  ->method('setData')
102  ->will($this->returnSelf());
103 
104  $this->_instance->create('1385661590', 'snapshot');
105  }
106 
107  public function testCreateInvalid()
108  {
109  $this->_backupModel->expects($this->never())->method('setType');
110  $this->_backupModel->expects($this->never())->method('setTime');
111  $this->_backupModel->expects($this->never())->method('setName');
112  $this->_backupModel->expects($this->never())->method('setPath');
113 
114  $this->_instance->create('451094400', 'snapshot');
115  }
116 }