1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Bug11200 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ class Bug11200SplFileObjectTests
8
+ {
9
+ public function fflush () : void
10
+ {
11
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
12
+ assertType ('bool ' , $ file ->eof ());
13
+ if ( $ file ->eof () )
14
+ {
15
+ return ;
16
+ }
17
+ assertType ('false ' , $ file ->eof ());
18
+ // call method that has side effects
19
+ $ file ->fflush ();
20
+ // the value of eof may have changed
21
+ assertType ('bool ' , $ file ->eof ());
22
+ }
23
+
24
+ public function fgetc () : void
25
+ {
26
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
27
+ assertType ('bool ' , $ file ->eof ());
28
+ if ( $ file ->eof () )
29
+ {
30
+ return ;
31
+ }
32
+ assertType ('false ' , $ file ->eof ());
33
+ // call method that has side effects
34
+ $ file ->fgetc ();
35
+ // the value of eof may have changed
36
+ assertType ('bool ' , $ file ->eof ());
37
+ }
38
+
39
+ public function fgetcsv () : void
40
+ {
41
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
42
+ assertType ('bool ' , $ file ->eof ());
43
+ if ( $ file ->eof () )
44
+ {
45
+ return ;
46
+ }
47
+ assertType ('false ' , $ file ->eof ());
48
+ // call method that has side effects
49
+ $ file ->fgetcsv ();
50
+ // the value of eof may have changed
51
+ assertType ('bool ' , $ file ->eof ());
52
+ }
53
+
54
+ public function fgets () : void
55
+ {
56
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
57
+ assertType ('bool ' , $ file ->eof ());
58
+ if ( $ file ->eof () )
59
+ {
60
+ return ;
61
+ }
62
+ assertType ('false ' , $ file ->eof ());
63
+ // call method that has side effects
64
+ $ file ->fgets ();
65
+ // the value of eof may have changed
66
+ assertType ('bool ' , $ file ->eof ());
67
+ }
68
+
69
+ public function fpassthru () : void
70
+ {
71
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
72
+ assertType ('bool ' , $ file ->eof ());
73
+ if ( $ file ->eof () )
74
+ {
75
+ return ;
76
+ }
77
+ assertType ('false ' , $ file ->eof ());
78
+ // call method that has side effects
79
+ $ file ->fpassthru ();
80
+ // the value of eof may have changed
81
+ assertType ('bool ' , $ file ->eof ());
82
+ }
83
+
84
+ public function fputcsv () : void
85
+ {
86
+ // places file pointer at the start of the file
87
+ $ file = new \SplFileObject ('php://memory ' , 'rw+ ' );
88
+ assertType ('int|false ' , $ file ->ftell ());
89
+ if ($ file ->ftell () !== 0 )
90
+ {
91
+ return ;
92
+ }
93
+ assertType ('0 ' , $ file ->ftell ());
94
+ // This file is not empty.
95
+ // call method that has side effects
96
+ $ file ->fputcsv (['a ' ]);
97
+ // the value of ftell may have changed
98
+ assertType ('int|false ' , $ file ->ftell ());
99
+ }
100
+
101
+ public function fread () : void
102
+ {
103
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
104
+ assertType ('bool ' , $ file ->eof ());
105
+ if ( $ file ->eof () )
106
+ {
107
+ return ;
108
+ }
109
+ assertType ('false ' , $ file ->eof ());
110
+ // call method that has side effects
111
+ $ file ->fread (1 );
112
+ // the value of eof may have changed
113
+ assertType ('bool ' , $ file ->eof ());
114
+ }
115
+
116
+ public function fscanf () : void
117
+ {
118
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
119
+ assertType ('bool ' , $ file ->eof ());
120
+ if ( $ file ->eof () )
121
+ {
122
+ return ;
123
+ }
124
+ assertType ('false ' , $ file ->eof ());
125
+ // call method that has side effects
126
+ $ file ->fscanf ('%f ' );
127
+ // the value of eof may have changed
128
+ assertType ('bool ' , $ file ->eof ());
129
+ }
130
+
131
+ public function fseek () : void
132
+ {
133
+ // places file pointer at the start of the file
134
+ $ file = new \SplFileObject ('php://memory ' , 'rw+ ' );
135
+ assertType ('int|false ' , $ file ->ftell ());
136
+ if ($ file ->ftell () !== 0 )
137
+ {
138
+ return ;
139
+ }
140
+ assertType ('0 ' , $ file ->ftell ());
141
+ // This file is not empty.
142
+ // call method that has side effects
143
+ $ file ->fseek (1 ,\SEEK_SET );
144
+ // the value of ftell may have changed
145
+ assertType ('int|false ' , $ file ->ftell ());
146
+ }
147
+
148
+ public function ftruncate () : void
149
+ {
150
+ $ file = new \SplFileObject ('php://memory ' , 'r ' );
151
+ assertType ('bool ' , $ file ->eof ());
152
+ if ( $ file ->eof () )
153
+ {
154
+ return ;
155
+ }
156
+ assertType ('false ' , $ file ->eof ());
157
+ // call method that has side effects
158
+ $ file ->ftruncate (0 );
159
+ // the value of eof may have changed
160
+ assertType ('bool ' , $ file ->eof ());
161
+ }
162
+
163
+ public function fwrite () : void
164
+ {
165
+ // places file pointer at the start of the file
166
+ $ file = new \SplFileObject ('php://memory ' , 'rw+ ' );
167
+ assertType ('int|false ' , $ file ->ftell ());
168
+ if ($ file ->ftell () !== 0 )
169
+ {
170
+ return ;
171
+ }
172
+ assertType ('0 ' , $ file ->ftell ());
173
+ // This file is not empty.
174
+ // call method that has side effects
175
+ $ file ->fwrite ('a ' );
176
+ // the value of ftell may have changed
177
+ assertType ('int|false ' , $ file ->ftell ());
178
+ }
179
+
180
+ }
0 commit comments