| Total Complexity | 10 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 63 |