@@ -557,6 +557,50 @@ public function testExistsRemoteMimeNotAllowed()
557557 $ this ->assertStringContainsString ("type 'application/json' not allowed " , $ e ->getMessage ());
558558 }
559559 }
560+
561+ public function testExistsRemoteMissingContentLength ()
562+ {
563+ // A response without content-length when max_file_size is set must fail,
564+ // because the size cannot be verified upfront.
565+ $ mock = new MockHandler ([new Response (200 )]);
566+ $ handlerStack = HandlerStack::create ($ mock );
567+ $ client = new Client ([
568+ 'handler ' => $ handlerStack ,
569+ 'http_errors ' => false ,
570+ ]);
571+
572+ $ file = new GenericFile ('https://example.com/file ' );
573+ $ cache = new FileCache ([
574+ 'path ' => $ this ->cachePath ,
575+ 'max_file_size ' => 50 ,
576+ ], client: $ client );
577+
578+ try {
579+ $ cache ->exists ($ file );
580+ $ this ->fail ('Expected an Exception to be thrown. ' );
581+ } catch (Exception $ e ) {
582+ $ this ->assertStringContainsString ('content-length ' , $ e ->getMessage ());
583+ }
584+ }
585+
586+ public function testExistsRemoteMissingContentLengthNoLimit ()
587+ {
588+ // When max_file_size is -1 (no limit), a missing content-length is fine.
589+ $ mock = new MockHandler ([new Response (200 )]);
590+ $ handlerStack = HandlerStack::create ($ mock );
591+ $ client = new Client ([
592+ 'handler ' => $ handlerStack ,
593+ 'http_errors ' => false ,
594+ ]);
595+
596+ $ file = new GenericFile ('https://example.com/file ' );
597+ $ cache = new FileCache ([
598+ 'path ' => $ this ->cachePath ,
599+ 'max_file_size ' => -1 ,
600+ ], client: $ client );
601+
602+ $ this ->assertTrue ($ cache ->exists ($ file ));
603+ }
560604}
561605
562606class FileCacheStub extends FileCache
0 commit comments