@@ -150,21 +150,20 @@ public static function dataFileSizes(): array {
150150
151151 #[\PHPUnit \Framework \Attributes \DataProvider('dataFileSizes ' )]
152152 public function testFileSizes ($ size ): void {
153- if (str_starts_with (PHP_VERSION , '8.5 ' ) && getenv ('CI ' )) {
154- $ this ->markTestSkipped ('Test is unreliable and skipped on 8.5 ' );
155- }
156-
157153 $ this ->cleanupAfter ('testfilesizes ' );
158154 $ s3 = $ this ->getInstance ();
159155
160156 $ sourceStream = fopen ('php://memory ' , 'wb+ ' );
161157 $ writeChunkSize = 1024 ;
162- $ chunkCount = $ size / $ writeChunkSize ;
163- for ($ i = 0 ; $ i < $ chunkCount ; $ i ++) {
164- fwrite ($ sourceStream , str_repeat ('A ' ,
165- ($ i < $ chunkCount - 1 ) ? $ writeChunkSize : $ size - ($ i * $ writeChunkSize )
166- ));
158+ $ chunk = str_repeat ('A ' , $ writeChunkSize );
159+ $ remainingSize = $ size ;
160+
161+ while ($ remainingSize > 0 ) {
162+ $ bytesToWrite = min ($ writeChunkSize , $ remainingSize );
163+ fwrite ($ sourceStream , ($ bytesToWrite === $ writeChunkSize ) ? $ chunk : str_repeat ('A ' , $ bytesToWrite ));
164+ $ remainingSize -= $ bytesToWrite ;
167165 }
166+
168167 rewind ($ sourceStream );
169168 $ s3 ->writeObject ('testfilesizes ' , $ sourceStream );
170169
@@ -174,15 +173,17 @@ public function testFileSizes($size): void {
174173 $ result = $ s3 ->readObject ('testfilesizes ' );
175174
176175 // compare first 100 bytes
177- self ::assertEquals (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare first 100 bytes ' );
176+ self ::assertSame (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare first 100 bytes ' );
178177
179178 // compare last 100 bytes
180- fseek ($ result , $ size - 100 );
181- self ::assertEquals (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare last 100 bytes ' );
179+ self :: assertSame ( 0 , fseek ($ result , $ size - 100 ), ' Seek to last 100 bytes succeeds ' );
180+ self ::assertSame (str_repeat ('A ' , 100 ), fread ($ result , 100 ), 'Compare last 100 bytes ' );
182181
183182 // end of file reached
184- fseek ($ result , $ size );
185- self ::assertTrue (feof ($ result ), 'End of file reached ' );
183+ self ::assertSame (0 , fseek ($ result , $ size ), 'Seek to EOF succeeds ' );
184+ self ::assertSame ($ size , ftell ($ result ), 'Pointer is at the end of file ' );
185+ self ::assertSame ('' , fread ($ result , 1 ), 'Reading at end of file returns no bytes ' );
186+ self ::assertTrue (feof ($ result ), 'End of file reached after read attempt ' );
186187
187188 $ this ->assertNoUpload ('testfilesizes ' );
188189 }
0 commit comments