str_pad_variation4.phpt [plain text]
--TEST--
Test str_pad() function : usage variations - unexpected inputs for '$pad_type' argument
--FILE--
<?php
echo "*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***\n";
$unset_var = 'string_val';
unset($unset_var);
class sample {
public function __toString() {
return "sample object";
}
}
$pad_types = array (
0, 1, 2, -2,
2147483647,
-2147483648,
10.5,
-20.5,
10.1234567e10,
"abc",
"STR_PAD_LEFT",
"2",
"0x2",
"02",
array(),
array(0),
array(1, 2),
true,
false,
TRUE,
FALSE,
NULL,
null,
new sample(),
@$undefined_var,
@$unset_var
);
$input = "Test string";
$pad_length = 20;
$pad_string = "*";
$count = 1;
foreach($pad_types as $pad_type) {
echo "-- Iteration $count --\n";
var_dump( str_pad($input, $pad_length, $pad_string, $pad_type) );
$count ++;
}
?>
===DONE===
--EXPECTF--
*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***
-- Iteration 1 --
string(20) "*********Test string"
-- Iteration 2 --
string(20) "Test string*********"
-- Iteration 3 --
string(20) "****Test string*****"
-- Iteration 4 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 5 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 6 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 7 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 8 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 9 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 10 --
Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d
NULL
-- Iteration 11 --
Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d
NULL
-- Iteration 12 --
string(20) "****Test string*****"
-- Iteration 13 --
string(20) "****Test string*****"
-- Iteration 14 --
string(20) "****Test string*****"
-- Iteration 15 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 16 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 17 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 18 --
string(20) "Test string*********"
-- Iteration 19 --
string(20) "*********Test string"
-- Iteration 20 --
string(20) "Test string*********"
-- Iteration 21 --
string(20) "*********Test string"
-- Iteration 22 --
string(20) "*********Test string"
-- Iteration 23 --
string(20) "*********Test string"
-- Iteration 24 --
Warning: str_pad() expects parameter 4 to be long, object given in %s on line %d
NULL
-- Iteration 25 --
string(20) "*********Test string"
-- Iteration 26 --
string(20) "*********Test string"
===DONE===