floor12 /
yii2-module-backup
| 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\FolderBackupMaker; |
||||||
| 16 | use floor12\backup\tests\TestCase; |
||||||
| 17 | use Yii; |
||||||
| 18 | use yii\base\Exception; |
||||||
| 19 | |||||||
| 20 | class FolderBackupMakerTest extends TestCase |
||||||
| 21 | { |
||||||
| 22 | public function testCreateBackupFileExists() |
||||||
| 23 | { |
||||||
| 24 | $this->expectException(Exception::class); |
||||||
| 25 | $backupFilePath = Yii::getAlias('@app/data/sqlite.db'); |
||||||
| 26 | $creator = new FolderBackupMaker($backupFilePath, 'tmp'); |
||||||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
It seems like
$backupFilePath can also be of type false; however, parameter $backupFilePath of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
|
|||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | public function testCreateBackupTargetNotExists() |
||||||
| 30 | { |
||||||
| 31 | $this->expectException(Exception::class); |
||||||
| 32 | $backupFilePath = Yii::getAlias('@app/data/backup.tgz'); |
||||||
| 33 | $creator = new FolderBackupMaker($backupFilePath, 'not-exists'); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $backupFilePath of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
|
|||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | |||||||
| 37 | public function testCreateBackupSuccess() |
||||||
| 38 | { |
||||||
| 39 | $backupFilePath = Yii::getAlias('@app/data/backup.tgz'); |
||||||
| 40 | $targetFolder = Yii::getAlias('@app/unit'); |
||||||
| 41 | $creator = new FolderBackupMaker($backupFilePath, $targetFolder); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $backupFilePath of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
It seems like
$targetFolder can also be of type false; however, parameter $targetFolder of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
|
|||||||
| 42 | $this->assertTrue($creator->execute()); |
||||||
| 43 | $this->fileExists($backupFilePath); |
||||||
|
0 ignored issues
–
show
The call to
PHPUnit\Framework\Assert::fileExists() has too many arguments starting with $backupFilePath.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. Loading history...
|
|||||||
| 44 | unlink($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of unlink() 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
Loading history...
|
|||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | public function testCreateBackupSuccessWithIoNice() |
||||||
| 48 | { |
||||||
| 49 | $backupFilePath = Yii::getAlias('@app/data/backup.tgz'); |
||||||
| 50 | $targetFolder = Yii::getAlias('@app/data/folder_for_backup'); |
||||||
| 51 | |||||||
| 52 | $this->assertFileNotExists($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of PHPUnit\Framework\Assert::assertFileNotExists() 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
Loading history...
|
|||||||
| 53 | $creator = new FolderBackupMaker($backupFilePath, $targetFolder); |
||||||
|
0 ignored issues
–
show
It seems like
$targetFolder can also be of type false; however, parameter $targetFolder of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
It seems like
$backupFilePath can also be of type false; however, parameter $backupFilePath of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
|
|||||||
| 54 | $this->assertTrue($creator->execute()); |
||||||
| 55 | $this->assertFileExists($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of PHPUnit\Framework\Assert::assertFileExists() 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
Loading history...
|
|||||||
| 56 | unlink($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of unlink() 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
Loading history...
|
|||||||
| 57 | } |
||||||
| 58 | |||||||
| 59 | public function testCreateBackupSuccessWithChmod() |
||||||
| 60 | { |
||||||
| 61 | $backupFilePath = Yii::getAlias('@app/data/backup.tgz'); |
||||||
| 62 | $targetFolder = Yii::getAlias('@app/data/folder_for_backup'); |
||||||
| 63 | Yii::$app->getModule('backup')->chmod = 0700; |
||||||
| 64 | $this->assertFileNotExists($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of PHPUnit\Framework\Assert::assertFileNotExists() 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
Loading history...
|
|||||||
| 65 | $creator = new FolderBackupMaker($backupFilePath, $targetFolder); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $backupFilePath of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
It seems like
$targetFolder can also be of type false; however, parameter $targetFolder of floor12\backup\logic\Fol...kupMaker::__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
Loading history...
|
|||||||
| 66 | $this->assertTrue($creator->execute()); |
||||||
| 67 | $this->assertFileExists($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $filename of PHPUnit\Framework\Assert::assertFileExists() 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
Loading history...
|
|||||||
| 68 | $this->assertEquals('0700', $this->readPerms($backupFilePath)); |
||||||
|
0 ignored issues
–
show
It seems like
$backupFilePath can also be of type false; however, parameter $file of floor12\backup\tests\uni...pMakerTest::readPerms() 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
Loading history...
|
|||||||
| 69 | @unlink($backupFilePath); |
||||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink(). This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
It seems like
$backupFilePath can also be of type false; however, parameter $filename of unlink() 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
Loading history...
|
|||||||
| 70 | } |
||||||
| 71 | |||||||
| 72 | protected function readPerms(string $file) |
||||||
| 73 | { |
||||||
| 74 | return substr(sprintf('%o', fileperms($file)), -4); |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | |||||||
| 78 | } |
||||||
| 79 |