Passed
Push — master ( c73d10...c1344b )
by Stefan
06:00
created

TestHelperTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 1
b 0
f 1
wmc 5
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Test\PNServer;
5
6
/**
7
 * Various auxiliary functions and values ​​required by some tests to set up 
8
 * the necessary test conditions.
9
 * 
10
 * @author Stefanius <[email protected]>
11
 * @copyright MIT License - see the LICENSE file for details
12
 */
13
trait TestHelperTrait
14
{
15
    protected static string $strSQLiteDBFilename = 'testdb.sqlite';
16
        
17
    protected function loadSubscription(string $strFilename) : string
18
    {
19
        return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'testdata' . DIRECTORY_SEPARATOR . $strFilename);
20
    }
21
    
22
    protected static function getTempDataDir() : string
23
    {
24
        $strTmpDir = __DIR__ . DIRECTORY_SEPARATOR . 'tempdata';
25
        if (!file_exists($strTmpDir)) {
26
            mkdir($strTmpDir);
27
        }
28
        chmod($strTmpDir, 0777);
29
        return $strTmpDir;
30
    }
31
    
32
    protected static function deleteTempDataFile() : void
33
    {
34
        $strFullPath = self::getTempDataDir() . DIRECTORY_SEPARATOR . self::$strSQLiteDBFilename;
35
        if (file_exists($strFullPath)) {
36
            unlink($strFullPath);
37
        }
38
    }
39
}