1
0
mirror of https://github.com/php/php-src.git synced 2026-04-11 10:03:18 +02:00
Files
archived-php-src/ext/mbstring/tests/mb_str_split_error_conditions.phpt
George Peter Banyard d44ee9112f Promote mb_str_split warning to ValueError
Also add a TODO about documenting this funcion on PHP.net
Convert some checks to assertions as if they don't hold something went wrong during memory allocation
Due to these changes this function cannot return false anymore, fix stubs accordingly
2020-04-02 22:40:00 +02:00

34 lines
786 B
PHP

--TEST--
mb_str_split() error conditions
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--FILE--
<?php
$string = "日本"; /* 2 chars */
// Invalid split length
try {
mb_str_split($string, 0);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
mb_str_split($string, -5);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
//Invalid Encoding
try {
mb_str_split($string, 1, "BAD_ENCODING");
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
mb_str_split(): Argument #2 ($split_length) must be greater than 0
mb_str_split(): Argument #2 ($split_length) must be greater than 0
mb_str_split(): Argument #3 ($encoding) must be a valid encoding, "BAD_ENCODING" given