vfprintf_variation1.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. Test vfprintf() function : variation functionality
  3. --CREDITS--
  4. Felix De Vliegher <felix.devliegher@gmail.com>
  5. --INI--
  6. precision=14
  7. --FILE--
  8. <?php
  9. echo "*** Testing vfprintf() : variation functionality ***\n";
  10. // Open handle
  11. $file = 'vfprintf_variation1.txt';
  12. $fp = fopen( $file, 'a+' );
  13. $funset = fopen( __FILE__, 'r' );
  14. unset( $funset );
  15. class FooClass
  16. {
  17. public function __toString()
  18. {
  19. return "Object";
  20. }
  21. }
  22. // Output facilitating function
  23. function writeAndDump($fp, $format, $args)
  24. {
  25. try {
  26. ftruncate( $fp, 0 );
  27. $length = vfprintf( $fp, $format, $args );
  28. rewind( $fp );
  29. $content = stream_get_contents( $fp );
  30. var_dump( $content );
  31. var_dump( $length );
  32. } catch (TypeError $exception) {
  33. echo $exception->getMessage() . "\n";
  34. }
  35. }
  36. // Test vfprintf()
  37. writeAndDump( $fp, "format", null );
  38. writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
  39. writeAndDump( $fp, "Foobar testing", array() );
  40. writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
  41. writeAndDump( $fp, "%02d", array( 50 ) );
  42. writeAndDump( $fp, "", array() );
  43. writeAndDump( $fp, "Testing %b %d %f %o %s %x %X", array( 9, 6, 2.5502, 24, "foobar", 15, 65 ) );
  44. // Close handle
  45. fclose( $fp );
  46. ?>
  47. --CLEAN--
  48. <?php
  49. $file = 'vfprintf_variation1.txt';
  50. unlink( $file );
  51. ?>
  52. --EXPECT--
  53. *** Testing vfprintf() : variation functionality ***
  54. vfprintf(): Argument #3 ($values) must be of type array, null given
  55. string(17) "Foo is 30 and bar"
  56. int(17)
  57. string(14) "Foobar testing"
  58. int(14)
  59. string(11) "bar bar bar"
  60. int(11)
  61. string(2) "50"
  62. int(2)
  63. string(0) ""
  64. int(0)
  65. string(38) "Testing 1001 6 2.550200 30 foobar f 41"
  66. int(38)