|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: floor12 |
|
5
|
|
|
* Date: 11.11.2019 |
|
6
|
|
|
* Time: 07:45 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace floor12\backup\tests\unit; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This is a tests for Backup class |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
use floor12\backup\logic\FolderBackupRestorer; |
|
16
|
|
|
use floor12\backup\tests\TestCase; |
|
17
|
|
|
use Yii; |
|
18
|
|
|
use yii\base\Exception; |
|
19
|
|
|
|
|
20
|
|
|
class FolderBackupRestorerTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testFolderNoExists() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->expectException(Exception::class); |
|
25
|
|
|
$this->expectExceptionMessage('Target folder don`t exist.'); |
|
26
|
|
|
$backupFilePath = Yii::getAlias('@app/data/folder.zip'); |
|
27
|
|
|
$targetFolder = Yii::getAlias('@app/no-exists'); |
|
28
|
|
|
new FolderBackupRestorer($backupFilePath, $targetFolder); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testFileNoExists() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->expectException(Exception::class); |
|
34
|
|
|
$this->expectExceptionMessage('Backup file don`t exist.'); |
|
35
|
|
|
$backupFilePath = Yii::getAlias('@app/data/no-exist.tgz'); |
|
36
|
|
|
$targetFolder = Yii::getAlias('@app/data/'); |
|
37
|
|
|
new FolderBackupRestorer($backupFilePath, $targetFolder); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testRestoreSuccess() |
|
41
|
|
|
{ |
|
42
|
|
|
$fileFromBackup = Yii::getAlias('@app/data/exists_test_file.txt'); |
|
43
|
|
|
$backupFilePath = Yii::getAlias('@app/data/folder.zip'); |
|
44
|
|
|
$targetFolder = Yii::getAlias('@app/data/'); |
|
45
|
|
|
@unlink($fileFromBackup); |
|
|
|
|
|
|
46
|
|
|
$this->assertFileNotExists($fileFromBackup); |
|
|
|
|
|
|
47
|
|
|
$restorer = new FolderBackupRestorer($backupFilePath, $targetFolder); |
|
|
|
|
|
|
48
|
|
|
$restorer->execute(); |
|
49
|
|
|
$this->assertFileExists($fileFromBackup); |
|
|
|
|
|
|
50
|
|
|
@unlink($fileFromBackup); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|