xref: /PHP-8.2/ext/bz2/tests/002.phpt (revision 56f90492)
1--TEST--
2bzopen() using fd opened in wrong mode
3--EXTENSIONS--
4bz2
5--FILE--
6<?php
7
8@unlink("bz_open_002.txt");
9
10$fp = fopen("bz_open_002.txt", "w");
11var_dump(bzopen($fp, "w"));
12
13$fp = fopen("bz_open_002.txt", "r");
14var_dump(bzopen($fp, "r"));
15
16@unlink("bz_open_002.txt");
17$fp = fopen("bz_open_002.txt", "x");
18var_dump(bzopen($fp, "w"));
19
20@unlink("bz_open_002.txt");
21$fp = fopen("bz_open_002.txt", "x");
22var_dump(bzopen($fp, "r"));
23
24$fp = fopen("bz_open_002.txt", "rb");
25var_dump(bzopen($fp, "r"));
26
27$fp = fopen("bz_open_002.txt", "wb");
28var_dump(bzopen($fp, "w"));
29
30$fp = fopen("bz_open_002.txt", "br");
31try {
32    var_dump(bzopen($fp, "r"));
33} catch (\TypeError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37$fp = fopen("bz_open_002.txt", "br");
38try {
39    var_dump(bzopen($fp, "w"));
40} catch (\TypeError $e) {
41    echo $e->getMessage() . \PHP_EOL;
42}
43
44$fp = fopen("bz_open_002.txt", "r");
45var_dump(bzopen($fp, "w"));
46
47$fp = fopen("bz_open_002.txt", "w");
48var_dump(bzopen($fp, "r"));
49
50$fp = fopen("bz_open_002.txt", "rw");
51var_dump(bzopen($fp, "w"));
52
53$fp = fopen("bz_open_002.txt", "rw");
54var_dump(bzopen($fp, "r"));
55
56$fp = fopen("bz_open_002.txt", "wr");
57var_dump(bzopen($fp, "w"));
58
59$fp = fopen("bz_open_002.txt", "wr");
60var_dump(bzopen($fp, "r"));
61
62$fp = fopen("bz_open_002.txt", "r+");
63var_dump(bzopen($fp, "r"));
64
65$fp = fopen("bz_open_002.txt", "r+");
66var_dump(bzopen($fp, "w"));
67
68$fp = fopen("bz_open_002.txt", "w+");
69var_dump(bzopen($fp, "r"));
70
71$fp = fopen("bz_open_002.txt", "w+");
72var_dump(bzopen($fp, "w"));
73
74$fp = fopen("bz_open_002.txt", "a");
75var_dump(bzopen($fp, "r"));
76
77$fp = fopen("bz_open_002.txt", "a");
78var_dump(bzopen($fp, "w"));
79
80@unlink("bz_open_002.txt");
81
82?>
83--EXPECTF--
84resource(%d) of type (stream)
85resource(%d) of type (stream)
86resource(%d) of type (stream)
87
88Warning: bzopen(): Cannot read from a stream opened in write only mode in %s on line %d
89bool(false)
90resource(%d) of type (stream)
91resource(%d) of type (stream)
92
93Warning: fopen(bz_open_002.txt): Failed to open stream: `br' is not a valid mode for fopen in %s on line %d
94bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
95
96Warning: fopen(bz_open_002.txt): Failed to open stream: `br' is not a valid mode for fopen in %s on line %d
97bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
98
99Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d
100bool(false)
101
102Warning: bzopen(): Cannot read from a stream opened in write only mode in %s on line %d
103bool(false)
104
105Warning: bzopen(): Cannot use stream opened in mode 'rw' in %s on line %d
106bool(false)
107
108Warning: bzopen(): Cannot use stream opened in mode 'rw' in %s on line %d
109bool(false)
110
111Warning: bzopen(): Cannot use stream opened in mode 'wr' in %s on line %d
112bool(false)
113
114Warning: bzopen(): Cannot use stream opened in mode 'wr' in %s on line %d
115bool(false)
116
117Warning: bzopen(): Cannot use stream opened in mode 'r+' in %s on line %d
118bool(false)
119
120Warning: bzopen(): Cannot use stream opened in mode 'r+' in %s on line %d
121bool(false)
122
123Warning: bzopen(): Cannot use stream opened in mode 'w+' in %s on line %d
124bool(false)
125
126Warning: bzopen(): Cannot use stream opened in mode 'w+' in %s on line %d
127bool(false)
128
129Warning: bzopen(): Cannot read from a stream opened in write only mode in %s on line %d
130bool(false)
131resource(%d) of type (stream)
132