@@ -451,4 +451,89 @@ public function resumableUploadThrowsNetworkExceptionOnChunkUploadFailure(): voi
451451 $ this ->client ->resumableUpload ('http://a.b ' , $ fileResource , 'file.txt ' , 9 );
452452 fclose ($ fileResource );
453453 }
454+
455+ #[Test]
456+ public function resumableUploadSuccessfullyUploadsSingleChunk (): void
457+ {
458+ $ fileContents = 'test-data ' ;
459+ $ fileResource = fopen ('php://memory ' , 'w+ ' );
460+ fwrite ($ fileResource , $ fileContents );
461+ rewind ($ fileResource );
462+
463+ $ uploadUrl = 'http://a.b ' ;
464+ $ fileName = 'file.txt ' ;
465+ $ fileSize = strlen ($ fileContents );
466+
467+ $ this ->requestFactoryMock ->method ('createRequest ' )->willReturn ($ this ->requestMock );
468+ $ this ->requestMock ->method ('withBody ' )->willReturnSelf ();
469+ $ this ->requestMock ->method ('withHeader ' )->willReturnSelf ();
470+
471+ $ this ->httpClientMock
472+ ->expects ($ this ->once ())
473+ ->method ('sendRequest ' )
474+ ->with ($ this ->requestMock )
475+ ->willReturn ($ this ->responseMock );
476+
477+ $ this ->responseMock ->method ('getStatusCode ' )->willReturn (200 );
478+ $ this ->streamMock ->method ('__toString ' )->willReturn ('<retval>1</retval> ' );
479+
480+ $ result = $ this ->client ->resumableUpload ($ uploadUrl , $ fileResource , $ fileName , $ fileSize );
481+
482+ $ this ->assertSame ('<retval>1</retval> ' , $ result );
483+ fclose ($ fileResource );
484+ }
485+
486+ #[Test]
487+ public function resumableUploadSuccessfullyUploadsMultipleChunks (): void
488+ {
489+ $ fileContents = str_repeat ('A ' , 3 * 1024 * 1024 ); // 3 MB
490+ $ fileResource = fopen ('php://memory ' , 'w+ ' );
491+ fwrite ($ fileResource , $ fileContents );
492+ rewind ($ fileResource );
493+
494+ $ uploadUrl = 'http://a.b ' ;
495+ $ fileName = 'bigfile.bin ' ;
496+ $ fileSize = strlen ($ fileContents );
497+
498+ $ this ->requestFactoryMock ->method ('createRequest ' )->willReturn ($ this ->requestMock );
499+ $ this ->requestMock ->method ('withBody ' )->willReturnSelf ();
500+ $ this ->requestMock ->method ('withHeader ' )->willReturnSelf ();
501+
502+ $ this ->httpClientMock
503+ ->expects ($ this ->exactly (3 ))
504+ ->method ('sendRequest ' )
505+ ->willReturnOnConsecutiveCalls (
506+ $ this ->responseMock ,
507+ $ this ->responseMock ,
508+ $ this ->responseMock ,
509+ );
510+
511+ $ this ->responseMock ->method ('getStatusCode ' )->willReturn (200 );
512+ $ this ->streamMock
513+ ->method ('__toString ' )
514+ ->willReturnOnConsecutiveCalls ('' , '' , '<retval>1</retval> ' );
515+
516+ $ result = $ this ->client ->resumableUpload ($ uploadUrl , $ fileResource , $ fileName , $ fileSize , 1024 * 1024 );
517+
518+ $ this ->assertSame ('<retval>1</retval> ' , $ result );
519+ fclose ($ fileResource );
520+ }
521+
522+ #[Test]
523+ public function resumableUploadStopsOnEmptyChunk (): void
524+ {
525+ $ fileResource = fopen ('php://memory ' , 'w+ ' );
526+ rewind ($ fileResource );
527+
528+ $ uploadUrl = 'http://a.b ' ;
529+ $ fileName = 'empty.txt ' ;
530+
531+ $ this ->requestFactoryMock ->expects ($ this ->never ())->method ('createRequest ' );
532+ $ this ->httpClientMock ->expects ($ this ->never ())->method ('sendRequest ' );
533+
534+ $ result = $ this ->client ->resumableUpload ($ uploadUrl , $ fileResource , $ fileName , 100 );
535+
536+ $ this ->assertSame ('' , $ result );
537+ fclose ($ fileResource );
538+ }
454539}
0 commit comments