@@ -144,21 +144,20 @@ public static function dataFileSizes(): array {
144144
145145 #[\PHPUnit \Framework \Attributes \DataProvider('dataFileSizes ' )]
146146 public function testFileSizes ($ size ): void {
147- if (str_starts_with (PHP_VERSION , '8.3 ' ) && getenv ('CI ' )) {
148- $ this ->markTestSkipped ('Test is unreliable and skipped on 8.3 ' );
149- }
150-
151147 $ this ->cleanupAfter ('testfilesizes ' );
152148 $ s3 = $ this ->getInstance ();
153149
154150 $ sourceStream = fopen ('php://memory ' , 'wb+ ' );
155151 $ writeChunkSize = 1024 ;
156- $ chunkCount = $ size / $ writeChunkSize ;
157- for ($ i = 0 ; $ i < $ chunkCount ; $ i ++) {
158- fwrite ($ sourceStream , str_repeat ('A ' ,
159- ($ i < $ chunkCount - 1 ) ? $ writeChunkSize : $ size - ($ i * $ writeChunkSize )
160- ));
152+ $ chunk = str_repeat ('A ' , $ writeChunkSize );
153+ $ remainingSize = $ size ;
154+
155+ while ($ remainingSize > 0 ) {
156+ $ bytesToWrite = min ($ writeChunkSize , $ remainingSize );
157+ fwrite ($ sourceStream , ($ bytesToWrite === $ writeChunkSize ) ? $ chunk : str_repeat ('A ' , $ bytesToWrite ));
158+ $ remainingSize -= $ bytesToWrite ;
161159 }
160+
162161 rewind ($ sourceStream );
163162 $ s3 ->writeObject ('testfilesizes ' , $ sourceStream );
164163
@@ -168,16 +167,21 @@ public function testFileSizes($size): void {
168167 $ result = $ s3 ->readObject ('testfilesizes ' );
169168
170169 // compare first 100 bytes
171- self ::assertEquals (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare first 100 bytes ' );
170+ self ::assertSame (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare first 100 bytes ' );
172171
173172 // compare last 100 bytes
174- fseek ($ result , $ size - 100 );
175- self ::assertEquals (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare last 100 bytes ' );
173+ self :: assertSame ( 0 , fseek ($ result , $ size - 100 ), ' Seek to last 100 bytes succeeds ' );
174+ self ::assertSame (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare last 100 bytes ' );
176175
177176 // end of file reached
178- fseek ($ result , $ size );
179- self ::assertTrue (feof ($ result ), 'End of file reached ' );
177+ self ::assertSame (0 , fseek ($ result , $ size ), 'Seek to EOF succeeds ' );
178+ self ::assertSame ($ size , ftell ($ result ), 'Pointer is at the end of file ' );
179+ self ::assertSame ('' , fread ($ result , 1 ), 'Reading at end of file returns no bytes ' );
180+ self ::assertTrue (feof ($ result ), 'End of file reached after read attempt ' );
180181
181182 $ this ->assertNoUpload ('testfilesizes ' );
183+
184+ fclose ($ sourceStream );
185+ fclose ($ result );
182186 }
183187}
0 commit comments