preg_grep_error.phpt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test preg_grep() function : error conditions - wrong numbers of parameters
  3. --FILE--
  4. <?php
  5. /*
  6. * proto array preg_grep(string regex, array input [, int flags])
  7. * Function is implemented in ext/pcre/php_pcre.c
  8. */
  9. echo "*** Testing preg_grep() : error conditions ***\n";
  10. // Zero arguments
  11. echo "\n-- Testing preg_grep() function with Zero arguments --\n";
  12. var_dump(preg_grep());
  13. //Test preg_grep with one more than the expected number of arguments
  14. echo "\n-- Testing preg_grep() function with more than expected no. of arguments --\n";
  15. $regex = '/\d/';
  16. $input = array(1, 2);
  17. $flags = 0;
  18. $extra_arg = 10;
  19. var_dump(preg_grep($regex, $input, $flags, $extra_arg));
  20. // Testing preg_grep withone less than the expected number of arguments
  21. echo "\n-- Testing preg_grep() function with less than expected no. of arguments --\n";
  22. $regex = 'string_val';
  23. var_dump(preg_grep($regex));
  24. echo "Done"
  25. ?>
  26. --EXPECTF--
  27. *** Testing preg_grep() : error conditions ***
  28. -- Testing preg_grep() function with Zero arguments --
  29. Warning: preg_grep() expects at least 2 parameters, 0 given in %spreg_grep_error.php on line %d
  30. NULL
  31. -- Testing preg_grep() function with more than expected no. of arguments --
  32. Warning: preg_grep() expects at most 3 parameters, 4 given in %spreg_grep_error.php on line %d
  33. NULL
  34. -- Testing preg_grep() function with less than expected no. of arguments --
  35. Warning: preg_grep() expects at least 2 parameters, 1 given in %spreg_grep_error.php on line %d
  36. NULL
  37. Done