Test Failed
Push — master ( eaa667...0d9623 )
by Evgenii
38:52
created

BackupImporterTest::testImportSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 14
rs 9.8666
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
It seems like $fileToImport can also be of type boolean; however, parameter $absoluteFilePath of floor12\backup\logic\BackupImporter::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $importer = new BackupImporter($config_id, /** @scrutinizer ignore-type */ $fileToImport);
Loading history...
Unused Code introduced by
The assignment to $importer is dead and can be removed.
Loading history...
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $importer is dead and can be removed.
Loading history...
Bug introduced by
It seems like $fileToImport can also be of type boolean; however, parameter $absoluteFilePath of floor12\backup\logic\BackupImporter::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $importer = new BackupImporter($config_id, /** @scrutinizer ignore-type */ $fileToImport);
Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $fileToImport can also be of type boolean; however, parameter $absoluteFilePath of floor12\backup\logic\BackupImporter::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $importer = new BackupImporter($config_id, /** @scrutinizer ignore-type */ $fileToImport);
Loading history...
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