chop_variation3.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --TEST--
  2. Test chop() function : usage variations - with heredoc string
  3. --FILE--
  4. <?php
  5. /*
  6. * Testing chop() : with heredoc strings
  7. */
  8. echo "*** Testing chop() : with heredoc strings ***\n";
  9. // defining different heredoc strings
  10. $empty_heredoc = <<<EOT
  11. EOT;
  12. $heredoc_with_newline = <<<EOT
  13. \n
  14. EOT;
  15. $heredoc_with_characters = <<<EOT
  16. first line of heredoc string
  17. second line of heredoc string
  18. third line of heredocstring
  19. EOT;
  20. $heredoc_with_newline_and_tabs = <<<EOT
  21. hello\tworld\nhello\nworld\n
  22. EOT;
  23. $heredoc_with_alphanumerics = <<<EOT
  24. hello123world456
  25. 1234hello\t1234
  26. EOT;
  27. $heredoc_with_embedded_nulls = <<<EOT
  28. hello\0world\0hello
  29. \0hello\0
  30. EOT;
  31. $heredoc_strings = array(
  32. $empty_heredoc,
  33. $heredoc_with_newline,
  34. $heredoc_with_characters,
  35. $heredoc_with_newline_and_tabs,
  36. $heredoc_with_alphanumerics,
  37. $heredoc_with_embedded_nulls
  38. );
  39. $count = 1;
  40. foreach($heredoc_strings as $string) {
  41. echo "\n--- Iteration $count ---\n";
  42. var_dump( chop($string) );
  43. var_dump( chop($string, "12345o\0\n\t") );
  44. $count++;
  45. }
  46. echo "Done\n";
  47. ?>
  48. --EXPECTF--
  49. *** Testing chop() : with heredoc strings ***
  50. --- Iteration 1 ---
  51. string(0) ""
  52. string(0) ""
  53. --- Iteration 2 ---
  54. string(0) ""
  55. string(0) ""
  56. --- Iteration 3 ---
  57. string(86) "first line of heredoc string
  58. second line of heredoc string
  59. third line of heredocstring"
  60. string(86) "first line of heredoc string
  61. second line of heredoc string
  62. third line of heredocstring"
  63. --- Iteration 4 ---
  64. string(23) "hello world
  65. hello
  66. world"
  67. string(23) "hello world
  68. hello
  69. world"
  70. --- Iteration 5 ---
  71. string(31) "hello123world456
  72. 1234hello 1234"
  73. string(25) "hello123world456
  74. 1234hell"
  75. --- Iteration 6 ---
  76. string(24) "hello%0world%0hello
  77. %0hello"
  78. string(23) "hello%0world%0hello
  79. %0hell"
  80. Done