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\models\Backup; |
||||
16 | use floor12\backup\tests\TestCase; |
||||
17 | use Yii; |
||||
18 | |||||
19 | class BackupTest extends TestCase |
||||
20 | { |
||||
21 | public function testGetFullPathWithEmptyFilename() |
||||
22 | { |
||||
23 | $model = new Backup(); |
||||
24 | $this->assertNull($model->filename); |
||||
25 | $this->assertNull($model->getFullPath()); |
||||
26 | } |
||||
27 | |||||
28 | public function testGetFullPathWithFilename() |
||||
29 | { |
||||
30 | $model = new Backup(); |
||||
31 | $model->filename = rand(0, 999); |
||||
32 | $path = Yii::getAlias($this->module->backupFolder) . DIRECTORY_SEPARATOR . $model->filename; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
33 | $this->assertEquals($path, $model->getFullPath()); |
||||
34 | } |
||||
35 | |||||
36 | public function testUpdateFileSizeWithNoFile() |
||||
37 | { |
||||
38 | $model = new Backup(); |
||||
39 | $this->assertNull($model->filename); |
||||
40 | $model->updateFileSize(); |
||||
41 | $this->assertEquals(0, $model->size); |
||||
42 | } |
||||
43 | |||||
44 | public function testUpdateFileSizeWithFile() |
||||
45 | { |
||||
46 | $fileToCheckSize = 'sqlite.db'; |
||||
47 | $fileToCheckSizePath = Yii::getAlias($this->module->backupFolder) . DIRECTORY_SEPARATOR . $fileToCheckSize; |
||||
0 ignored issues
–
show
Are you sure
Yii::getAlias($this->module->backupFolder) of type false|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
48 | $model = new Backup(); |
||||
49 | $model->filename = $fileToCheckSize; |
||||
50 | $model->updateFileSize(); |
||||
51 | $this->assertEquals(filesize($fileToCheckSizePath), $model->size); |
||||
52 | } |
||||
53 | |||||
54 | public function testUnlinkFileAfterDelete() |
||||
55 | { |
||||
56 | $fileToCheckSize = 'test_backup.tgz'; |
||||
57 | $fileToCheckSizePath = Yii::getAlias($this->module->backupFolder) . DIRECTORY_SEPARATOR . $fileToCheckSize; |
||||
0 ignored issues
–
show
Are you sure
Yii::getAlias($this->module->backupFolder) of type false|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
58 | file_put_contents($fileToCheckSizePath, 'this is a test file content'); |
||||
59 | $model = new Backup(); |
||||
60 | $model->filename = $fileToCheckSize; |
||||
61 | $this->assertFileExists($fileToCheckSizePath); |
||||
62 | $model->delete(); |
||||
63 | $this->assertFileNotExists($fileToCheckSizePath); |
||||
64 | } |
||||
65 | |||||
66 | |||||
67 | } |