21 private $objectManager;
31 private $directoryList;
65 $this->objectManager = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
66 $this->log = $this->createMock(\
Magento\Framework\Setup\LoggerInterface::class);
67 $this->directoryList = $this->createMock(\
Magento\Framework\
App\
Filesystem\DirectoryList::class);
68 $this->path = realpath(
__DIR__);
69 $this->directoryList->expects($this->any())
71 ->willReturn($this->path);
72 $this->directoryList->expects($this->any())
74 ->willReturn($this->path);
76 $this->filesystem = $this->createMock(\
Magento\Framework\Backup\Filesystem::class);
77 $this->database = $this->createMock(\
Magento\Framework\Backup\Db::class);
78 $this->helper = $this->createMock(\
Magento\Framework\Backup\
Filesystem\Helper::class);
79 $this->helper->expects($this->any())
81 ->willReturn([
'writable' =>
true,
'size' => 100]);
83 $configLoader->expects($this->any())
86 $this->objectManager->expects($this->any())
88 ->will($this->returnValueMap([
94 $this->objectManager->expects($this->any())
96 ->will($this->returnValueMap([
98 [\
Magento\Framework\Backup\Filesystem::class, [], $this->filesystem],
99 [\
Magento\Framework\Backup\Db::class, [], $this->database],
102 $this->objectManager,
104 $this->directoryList,
112 $this->setupCodeBackupRollback();
113 $this->filesystem->expects($this->once())
115 $this->file->expects($this->once())->method(
'isExists')->with($this->path .
'/backups')->willReturn(
false);
116 $this->file->expects($this->once())->method(
'createDirectory')->with($this->path .
'/backups', 0777);
117 $this->model->codeBackup(
time());
126 $this->model->codeBackup(
time(),
'txt');
131 $this->filesystem->expects($this->once())->method(
'rollback');
132 $this->setupCodeBackupRollback();
133 $this->file->expects($this->once())
135 ->with($this->path .
'/backups/12345_filesystem_code.tgz')
137 $this->model->codeRollback(
'12345_filesystem_code.tgz');
146 $this->file->expects($this->once())
149 $this->model->codeRollback(
'12345_filesystem_code.tgz');
158 $this->model->codeRollback(
'RollbackFile_A.txt');
163 $this->setupCodeBackupRollback();
164 $this->filesystem->expects($this->once())
166 $this->file->expects($this->once())->method(
'isExists')->with($this->path .
'/backups')->willReturn(
false);
167 $this->file->expects($this->once())->method(
'createDirectory')->with($this->path .
'/backups', 0777);
173 $this->filesystem->expects($this->once())->method(
'rollback');
174 $this->setupCodeBackupRollback();
175 $this->file->expects($this->once())
177 ->with($this->path .
'/backups/12345_filesystem_media.tgz')
184 $this->setupDbBackupRollback();
185 $this->database->expects($this->once())->method(
'getBackupFilename')->willReturn(
'RollbackFile_A.gz');
186 $this->database->expects($this->once())->method(
'create');
187 $this->file->expects($this->once())->method(
'isExists')->willReturn(
false);
188 $this->file->expects($this->once())->method(
'createDirectory');
189 $this->model->dbBackup(
time());
194 $this->setupDbBackupRollback();
196 $this->database->expects($this->once())->method(
'rollback');
197 $this->database->expects($this->exactly(2))->method(
'getBackupFilename')
198 ->willReturnOnConsecutiveCalls(
'test',
'1510140748_db_test_backup');
199 $this->database->expects($this->once())->method(
'getTime')->willReturn(1510140748);
200 $this->database->expects($this->once())->method(
'getType')->willReturn(
'db');
201 $this->database->expects($this->once())->method(
'setName')->with(
' test backup');
203 $this->file->expects($this->once())
205 ->with($this->path .
'/backups/1510140748_db_test_backup.sql')
208 $this->model->dbRollback(
'1510140748_db_test_backup.sql');
211 private function setupCodeBackupRollback()
213 $this->filesystem->expects($this->once())
214 ->method(
'addIgnorePaths');
215 $this->filesystem->expects($this->once())
216 ->method(
'setBackupsDir');
217 $this->filesystem->expects($this->once())
218 ->method(
'setBackupExtension');
219 $this->filesystem->expects($this->once())
221 $this->filesystem->expects($this->once())
222 ->method(
'getBackupFilename')
223 ->willReturn(
'RollbackFile_A.tgz');
224 $this->filesystem->expects($this->atLeastOnce())
225 ->method(
'getBackupPath')
226 ->willReturn(
'pathToFile/12345_filesystem_code.tgz');
227 $this->log->expects($this->once())
228 ->method(
'logSuccess');
231 private function setupDbBackupRollback()
233 $this->database->expects($this->once())
234 ->method(
'setBackupsDir');
235 $this->database->expects($this->once())
236 ->method(
'setBackupExtension');
237 $this->database->expects($this->once())
239 $this->database->expects($this->atLeastOnce())
240 ->method(
'getBackupPath')
241 ->willReturn(
'pathToFile/12345_db.sql');
242 $this->log->expects($this->once())
243 ->method(
'logSuccess');
248 $size = $this->model->getFSDiskSpace();
249 $this->assertEquals(100, $size);
254 $this->database->expects($this->once())->method(
'getDBSize')->willReturn(100);
255 $size = $this->model->getDBDiskSpace();
256 $this->assertEquals(100, $size);
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testCodeRollbackWithInvalidFileType()
testCodeBackupWithInvalidType()
testCodeRollbackWithInvalidFilePath()