php-src/ext/spl/tests/SplFileObject_setCsvControl_error002.phpt
Nikita Popov 625d8463a4 Consistent error handling for fgetcsv/fputcsv
Normalize the behavior between the file functions and those on
SplFileObject.

Be consistent about throwing regardless of whether the delimiter etc
is empty or has too many characters. I don't think it's worthwhile
to distinguish these cases.

Back when we looked into this originally, there was some hope that
we might want to add support for multiple-character delimiter etc,
but after a cursory look, I really don't think this is going to
happen (for fputcsv maybe, but for fgetcsv this just makes an already
broken function much more complicated.)

Closes GH-6188.
2020-09-23 10:11:04 +02:00

27 lines
599 B
PHP

--TEST--
SPL: SplFileObject::setCsvControl error 002
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--FILE--
<?php
file_put_contents('csv_control_data_error002.csv',
<<<CDATA
'groene appelen'|10
'gele bananen'|20
'rode kersen'|30
CDATA
);
$s = new SplFileObject('csv_control_data_error002.csv');
$s->setFlags(SplFileObject::READ_CSV);
try {
$s->setCsvControl('|', 'two');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--CLEAN--
<?php
unlink('csv_control_data_error002.csv');
?>
--EXPECT--
SplFileObject::setCsvControl(): Argument #2 ($enclosure) must be a single character