Completed
Push — master ( 55aead...307710 )
by Wilmer
02:36
created

Unit   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 28
c 1
b 0
f 0
dl 0
loc 54
rs 10
1
<?php
2
namespace terabytesoft\assets\fontawesome\tests\Helper;
3
4
// here you can define custom actions
5
// all public methods declared in helper class will be available in $I
6
7
class Unit extends \Codeception\Module
8
{
9
    /**
10
     * clearDirectory
11
     * @param string $dir directory to be cleared.
12
     */
13
    public function clearDirectory($dir): void
14
    {
15
        if (!is_dir($dir)) {
16
            return;
17
        }
18
        if (!($handle = opendir($dir))) {
19
            return;
20
        }
21
        $specialFileNames = [
22
            '.htaccess',
23
            '.gitignore',
24
            '.gitkeep',
25
            '.hgignore',
26
            '.hgkeep',
27
        ];
28
        while (($file = readdir($handle)) !== false) {
29
            if ($file === '.' || $file === '..') {
30
                continue;
31
            }
32
            if (in_array($file, $specialFileNames)) {
33
                continue;
34
            }
35
            $path = $dir . DIRECTORY_SEPARATOR . $file;
36
            if (is_dir($path)) {
37
                \yii\helpers\FileHelper::removeDirectory($path);
38
            } else {
39
                unlink($path);
40
            }
41
        }
42
        closedir($handle);
43
    }
44
45
    /**
46
     * sourcesPublishVerifyFiles
47
     *
48
     * @param string $type
49
     * @param array  $bundle
50
     */
51
    public function sourcesPublishVerifyFiles($type, $bundle): void
52
    {
53
        foreach ($bundle->$type as $filename) {
54
            $publishedFile = $bundle->basePath . DIRECTORY_SEPARATOR . $filename;
55
            $sourceFile = $bundle->sourcePath . DIRECTORY_SEPARATOR . $filename;
56
            \PHPUnit_Framework_Assert::assertFileExists($publishedFile);
57
            \PHPUnit_Framework_Assert::assertFileEquals($publishedFile, $sourceFile);
58
        }
59
60
        \PHPUnit_Framework_Assert::assertTrue(is_dir($bundle->basePath));
61
    }
62
}
63