Skip to content

Commit 186465b

Browse files
authored
QA - finfo_open - increase test coverage (#13839)
1 parent 4d7e3fc commit 186465b

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

ext/fileinfo/tests/finfo_open_001.phpt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ finfo_open(): Testing magic_file names
44
fileinfo
55
--FILE--
66
<?php
7-
87
try {
98
var_dump(finfo_open(FILEINFO_MIME, "\0"));
109
} catch (ValueError $e) {
@@ -17,6 +16,26 @@ var_dump(finfo_open(FILEINFO_MIME, 123));
1716
var_dump(finfo_open(FILEINFO_MIME, 1.0));
1817
var_dump(finfo_open(FILEINFO_MIME, '/foo/bar/inexistent'));
1918

19+
var_dump($obj = new finfo(FILEINFO_MIME, NULL));
20+
var_dump($obj = new finfo(FILEINFO_MIME, ''));
21+
22+
try {
23+
var_dump($obj = new finfo(FILEINFO_MIME, 123));
24+
} catch (\Exception $e) {
25+
echo $e->getMessage() . PHP_EOL;
26+
}
27+
28+
try {
29+
var_dump($obj = new finfo(FILEINFO_MIME, 1.0));
30+
} catch (\Exception $e) {
31+
echo $e->getMessage() . PHP_EOL;
32+
}
33+
34+
try {
35+
var_dump($obj = new finfo(FILEINFO_MIME, '/foo/bar/inexistent'));
36+
} catch (\Exception $e) {
37+
echo $e->getMessage() . PHP_EOL;
38+
}
2039
?>
2140
--EXPECTF--
2241
finfo_open(): Argument #2 ($magic_database) must not contain any null bytes
@@ -45,3 +64,10 @@ Warning: finfo_open(%sinexistent): Failed to open stream: No such file or direct
4564

4665
Warning: finfo_open(): Failed to load magic database at "%sinexistent" in %s on line %d
4766
bool(false)
67+
object(finfo)#%d (%d) {
68+
}
69+
object(finfo)#%d (%d) {
70+
}
71+
finfo::__construct(%s123): Failed to open stream: No such file or directory
72+
finfo::__construct(%s1): Failed to open stream: No such file or directory
73+
finfo::__construct(%sinexistent): Failed to open stream: No such file or directory
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
finfo_open(): Testing magic_file names
3+
--EXTENSIONS--
4+
fileinfo
5+
--FILE--
6+
<?php
7+
$buggyPath = str_repeat('a', PHP_MAXPATHLEN + 1);
8+
9+
var_dump(finfo_open(FILEINFO_MIME, $buggyPath));
10+
11+
try {
12+
$object = new finfo(FILEINFO_MIME, $buggyPath);
13+
} catch (\Exception $ex) {
14+
echo "TEST:" . $ex->getMessage() . PHP_EOL;
15+
}
16+
?>
17+
--EXPECTF--
18+
bool(false)
19+
TEST:Constructor failed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
finfo_open(): Testing magic_file names
3+
--EXTENSIONS--
4+
fileinfo
5+
--INI--
6+
open_basedir='.'
7+
--FILE--
8+
<?php
9+
$buggyPath = str_repeat('a', PHP_MAXPATHLEN + 1);
10+
11+
var_dump(finfo_open(FILEINFO_MIME, $buggyPath));
12+
13+
try {
14+
$object = new finfo(FILEINFO_MIME, $buggyPath);
15+
} catch (\Exception $ex) {
16+
echo "TEST:" . $ex->getMessage() . PHP_EOL;
17+
}
18+
?>
19+
--EXPECTF--
20+
Warning: finfo_open(): File name is longer than the maximum allowed path length on this platform (%d): %s in %s on line %d
21+
bool(false)
22+
TEST:finfo::__construct(): File name is longer than the maximum allowed path length on this platform (%d): %s

0 commit comments

Comments
 (0)