1--TEST--
2Test vfprintf() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--INI--
6precision=14
7--FILE--
8<?php
9function writeAndDump($fp, $format, $args)
10{
11    ftruncate( $fp, 0 );
12    $length = vfprintf( $fp, $format, $args );
13    rewind( $fp );
14    $content = stream_get_contents( $fp );
15    var_dump( $content );
16    var_dump( $length );
17}
18
19echo "*** Testing vfprintf() : basic functionality ***\n";
20
21// Open handle
22$file = 'vfprintf_basic.txt';
23$fp = fopen( $file, "a+" );
24
25// Test vfprintf()
26writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
27writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
28writeAndDump( $fp, "%d digit", array( '54' ) );
29writeAndDump( $fp, "%b %b", array( true, false ) );
30writeAndDump( $fp, "%c %c %c", array( 65, 66, 67 ) );
31writeAndDump( $fp, "%e %E %e", array( 1000, 2e4, +2e2 ) );
32writeAndDump( $fp, "%02d", array( 50 ) );
33writeAndDump( $fp, "Testing %b %d %f %s %x %X", array( 9, 6, 2.5502, "foobar", 15, 65 ) );
34
35// Close handle
36fclose( $fp );
37
38?>
39--CLEAN--
40<?php
41
42$file = 'vfprintf_basic.txt';
43unlink( $file );
44
45?>
46--EXPECT--
47*** Testing vfprintf() : basic functionality ***
48string(17) "Foo is 30 and bar"
49int(17)
50string(11) "bar bar bar"
51int(11)
52string(8) "54 digit"
53int(8)
54string(3) "1 0"
55int(3)
56string(5) "A B C"
57int(5)
58string(35) "1.000000e+3 2.000000E+4 2.000000e+2"
59int(35)
60string(2) "50"
61int(2)
62string(35) "Testing 1001 6 2.550200 foobar f 41"
63int(35)
64