summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/fgetcsv_error_conditions.phpt
blob: dd2b4d61d9fde2de236096e9811d2c2ef79491b7 (plain)
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
--TEST--
Various fgetcsv() error conditions
--FILE--
<?php

$file_name = __DIR__ . '/fgetcsv_error_conditions.csv';
$file_handle = fopen($file_name, 'r');

$length = 1024;
$delimiter = ',';
$enclosure = '"';

echo 'fgetcsv() with negative length' . \PHP_EOL;
try {
    var_dump( fgetcsv($file_handle, -10) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    var_dump( fgetcsv($file_handle, -10, $delimiter) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
try {
    var_dump( fgetcsv($file_handle, -10, $delimiter, $enclosure) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

echo 'fgetcsv() with delimiter as NULL' . \PHP_EOL;
try {
    var_dump( fgetcsv($file_handle, $length, NULL, $enclosure) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

echo 'fgetcsv() with enclosure as NULL' . \PHP_EOL;
try {
    var_dump( fgetcsv($file_handle, $length, $delimiter, NULL) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

echo 'fgetcsv() with delimiter & enclosure as NULL' . \PHP_EOL;
try {
    var_dump( fgetcsv($file_handle, $length, NULL, NULL) );
} catch (\ValueError $e) {
    echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
fgetcsv() with negative length
fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
fgetcsv() with delimiter as NULL
fgetcsv(): Argument #3 ($separator) must be a single character
fgetcsv() with enclosure as NULL
fgetcsv(): Argument #4 ($enclosure) must be a single character
fgetcsv() with delimiter & enclosure as NULL
fgetcsv(): Argument #3 ($separator) must be a single character