@@ -26,7 +26,8 @@ final class BinaryStreamResponseTest extends TestCase
2626 public function testSendContent (): void
2727 {
2828 $ ioServiceMock = $ this ->createMock (IOServiceInterface::class);
29- $ binaryStreamResponse = $ this ->prepareBinaryStreamResponse ($ ioServiceMock );
29+ $ request = $ this ->prepareRequest ();
30+ $ binaryStreamResponse = $ this ->prepareBinaryStreamResponse ($ ioServiceMock , $ request );
3031
3132 file_put_contents ('php://input ' , 'test data ' );
3233 $ in = fopen ('php://input ' , 'rb ' );
@@ -40,10 +41,42 @@ public function testSendContent(): void
4041 $ binaryStreamResponse ->sendContent ();
4142 }
4243
43- private function prepareBinaryStreamResponse (IOServiceInterface & MockObject $ ioServiceMock ): BinaryStreamResponse
44+ /**
45+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
46+ */
47+ public function testSendRangeContent (): void
48+ {
49+ $ ioServiceMock = $ this ->createMock (IOServiceInterface::class);
50+ $ request = $ this ->prepareRequest (['Range ' => 'bytes=0-499 ' ]);
51+ $ binaryStreamResponse = $ this ->prepareBinaryStreamResponse ($ ioServiceMock , $ request );
52+
53+ file_put_contents ('php://input ' , 'test data ' );
54+ $ in = fopen ('php://input ' , 'rb ' );
55+
56+ $ ioServiceMock
57+ ->expects (self ::once ())
58+ ->method ('getFileInputStream ' )
59+ ->with ($ binaryStreamResponse ->getFile ())
60+ ->willReturn ($ in );
61+
62+ $ binaryStreamResponse ->sendContent ();
63+ }
64+
65+ /**
66+ * @param array<string,string> $headers
67+ */
68+ private function prepareRequest (array $ headers = []): Request
4469 {
4570 $ request = new Request ();
71+ foreach ($ headers as $ name => $ value ) {
72+ $ request ->headers ->set ($ name , $ value );
73+ }
4674
75+ return $ request ;
76+ }
77+
78+ private function prepareBinaryStreamResponse (IOServiceInterface & MockObject $ ioServiceMock , Request $ request ): BinaryStreamResponse
79+ {
4780 $ binaryFile = new BinaryFile (['id ' => 'foo.jpg ' , 'size ' => 5321 ]);
4881 $ binaryStreamResponse = new BinaryStreamResponse ($ binaryFile , $ ioServiceMock );
4982
0 commit comments