-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilsTest.php
More file actions
71 lines (61 loc) · 1.97 KB
/
UtilsTest.php
File metadata and controls
71 lines (61 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types=1);
namespace Tests\CssManager;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-css-updater\CssManager\Utils
*
* @author fdipzone
*/
final class UtilsTest extends TestCase
{
/**
* @covers \CssManager\Utils::checkExtension
*/
public function testCheckExtension()
{
$file = '/tmp/test.jpg';
$ret = \CssManager\Utils::checkExtension($file, ['jpg', 'gif', 'png']);
$this->assertTrue($ret);
$ret = \CssManager\Utils::checkExtension($file, ['js', 'css']);
$this->assertFalse($ret);
}
/**
* @covers \CssManager\Utils::createDirs
*/
public function testCreateDirs()
{
$path = sprintf('/tmp/ut-%s-%s-%d/test', md5(__CLASS__), date('YmdHis'), \Tests\Utils\PHPUnitExtension::sequenceId());
$ret = \CssManager\Utils::createDirs($path);
$this->assertTrue($ret);
$this->assertTrue(is_dir($path));
// 再次创建
$ret = \CssManager\Utils::createDirs($path);
$this->assertTrue($ret);
$this->assertTrue(is_dir($path));
}
/**
* @covers \CssManager\Utils::log
*/
public function testLog()
{
$log_file = sprintf('/tmp/ut-%s-%s-%d/log/test.log', md5(__CLASS__), date('YmdHis'), \Tests\Utils\PHPUnitExtension::sequenceId());
$content = 'my log content';
\CssManager\Utils::log($log_file, $content);
$this->assertTrue(strstr(file_get_contents($log_file), $content)!==false);
}
/**
* @covers \CssManager\Utils::traversing
*/
public function testTraversing()
{
$path = dirname(dirname(__FILE__));
// 不遍历子目录,此目录中没有任何文件
$result1 = [];
\CssManager\Utils::traversing($path, $result1);
$this->assertTrue(count($result1)==0);
// 遍历子目录
$result2 = [];
\CssManager\Utils::traversing($path, $result2, true);
$this->assertTrue(count($result2)>0);
}
}