File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,7 +60,13 @@ public function getSize(): ?int
6060 */
6161 private function getSizeFromMetadata (): int
6262 {
63- foreach ($ this ->stream ->getMetadata ('wrapper_data ' ) as $ value ) {
63+ $ metadata = $ this ->stream ->getMetadata ('wrapper_data ' );
64+
65+ if (is_null ($ metadata )) {
66+ return 0 ;
67+ }
68+
69+ foreach ($ metadata as $ value ) {
6470 if (substr ($ value , 0 , 15 ) == 'Content-Length: ' ) {
6571 return (int ) substr ($ value , 16 );
6672 }
Original file line number Diff line number Diff line change @@ -73,4 +73,15 @@ public function testNoContentLengthHeader()
7373
7474 $ this ->assertEquals (0 , $ stream ->getSize ());
7575 }
76+
77+ public function testReturnsZeroWhenGetSizeIsZeroAndWrapperDataIsNull ()
78+ {
79+ $ httpStream = $ this ->prophesize (StreamInterface::class);
80+ $ httpStream ->getSize ()->willReturn (null );
81+ $ httpStream ->getMetadata ('wrapper_data ' )->willReturn (null );
82+
83+ $ stream = new ReadStream ($ httpStream ->reveal ());
84+
85+ $ this ->assertEquals (0 , $ stream ->getSize ());
86+ }
7687}
You can’t perform that action at this time.
0 commit comments