|
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
|
|
|
use floor12\backup\Exceptions\ConfigurationNotFoundException; |
|
12
|
|
|
use floor12\backup\Exceptions\ModuleNotConfiguredException; |
|
13
|
|
|
use floor12\backup\logic\BackupImporter; |
|
14
|
|
|
use floor12\backup\models\Backup; |
|
15
|
|
|
use floor12\backup\models\BackupStatus; |
|
16
|
|
|
use floor12\backup\tests\TestCase; |
|
17
|
|
|
use Yii; |
|
18
|
|
|
|
|
19
|
|
|
class BackupImporterTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
public function testEmptyConfigs() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->expectException(ModuleNotConfiguredException::class); |
|
25
|
|
|
$this->module->configs = []; |
|
26
|
|
|
$config_id = 'test_file_backup'; |
|
27
|
|
|
$fileToImport = Yii::getAlias('@app/data/postgres_for_import'); |
|
28
|
|
|
$importer = new BackupImporter($config_id, $fileToImport); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testWrongConfigName() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->expectException(ConfigurationNotFoundException::class); |
|
34
|
|
|
$fileToImport = Yii::getAlias('@app/data/postgres_for_import'); |
|
35
|
|
|
$config_id = 'config_not_exists'; |
|
36
|
|
|
$importer = new BackupImporter($config_id, $fileToImport); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testImportSuccess() |
|
40
|
|
|
{ |
|
41
|
|
|
Backup::deleteAll(); |
|
42
|
|
|
$config_id = 'postgres_db'; |
|
43
|
|
|
$fileName = 'postgres_for_import'; |
|
44
|
|
|
$fileToImport = Yii::getAlias("@app/data/{$fileName}"); |
|
45
|
|
|
$importer = new BackupImporter($config_id, $fileToImport); |
|
|
|
|
|
|
46
|
|
|
$this->assertTrue($importer->import()); |
|
47
|
|
|
$backup = Backup::findOne(['filename' => $fileName]); |
|
48
|
|
|
$this->assertIsObject($backup); |
|
49
|
|
|
$this->assertEquals(BackupStatus::IMPORTED, $backup->status); |
|
50
|
|
|
$this->assertEquals($config_id, $backup->config_id); |
|
51
|
|
|
$this->assertFileExists($backup->getFullPath()); |
|
52
|
|
|
$backup->delete(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|