Annotation of embedaddon/php/ext/standard/tests/file/file_put_contents_variation8.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test file_put_contents() function : usage variation - obscure filenames
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --SKIPIF--
6: <?php
7: if(substr(PHP_OS, 0, 3) == "WIN")
8: die("skip Not for Windows");
9: ?>
10: --FILE--
11: <?php
12: /* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
13: * Description: Write/Create a file with contents data and return the number of bytes written
14: * Source code: ext/standard/file.c
15: * Alias to functions:
16: */
17:
18: echo "*** Testing file_put_contents() : usage variation ***\n";
19:
20: /* An array of filenames */
21: $names_arr = array(
22: -1,
23: TRUE,
24: FALSE,
25: NULL,
26: "",
27: " ",
28: //this one also generates a java message rather than our own so we don't replicate php message
29: "\0",
30: array(),
31:
32: //the next 2 generate java messages so we don't replicate the php messages
33: "/no/such/file/dir",
34: "php/php"
35:
36: );
37:
38: for( $i=0; $i<count($names_arr); $i++ ) {
39: echo "-- Iteration $i --\n";
40: $res = file_put_contents($names_arr[$i], "Some data");
41: if ($res !== false && $res != null) {
42: echo "$res bytes written to: $names_arr[$i]\n";
43: unlink($names_arr[$i]);
44: }
45: else {
46: echo "Failed to write data to: $names_arr[$i]\n";
47: }
48: }
49:
50: echo "\n*** Done ***\n";
51: ?>
52: --EXPECTF--
53: *** Testing file_put_contents() : usage variation ***
54: -- Iteration 0 --
55: 9 bytes written to: -1
56: -- Iteration 1 --
57: 9 bytes written to: 1
58: -- Iteration 2 --
59:
60: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
61: Failed to write data to:
62: -- Iteration 3 --
63:
64: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
65: Failed to write data to:
66: -- Iteration 4 --
67:
68: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
69: Failed to write data to:
70: -- Iteration 5 --
71: 9 bytes written to:
72: -- Iteration 6 --
1.1.1.2 ! misho 73:
! 74: Warning: file_put_contents() expects parameter 1 to be a valid path, string given in %s on line %d
1.1 misho 75: Failed to write data to:
76: -- Iteration 7 --
77:
1.1.1.2 ! misho 78: Warning: file_put_contents() expects parameter 1 to be a valid path, array given in %s on line %d
! 79:
! 80: Notice: Array to string conversion in %s on line %d
1.1 misho 81: Failed to write data to: Array
82: -- Iteration 8 --
83:
84: Warning: file_put_contents(%sdir): failed to open stream: %s in %s on line %d
85: Failed to write data to: %sdir
86: -- Iteration 9 --
87:
88: Warning: file_put_contents(%sphp): failed to open stream: %s in %s on line %d
89: Failed to write data to: %sphp
90:
91: *** Done ***
92:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>