File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ final class PsrMessageStream implements StreamInterface
1616
1717 private bool $ isEof = false ;
1818
19+ private bool $ isClosed = false ;
20+
1921 private int $ position = 0 ;
2022
2123 public function __construct (private readonly ReadableStream $ source , private readonly ?int $ size = null )
@@ -32,6 +34,7 @@ public function close(): void
3234 $ this ->source ->close ();
3335 $ this ->buffer = '' ;
3436 $ this ->isEof = true ;
37+ $ this ->isClosed = true ;
3538 }
3639
3740 public function detach (): void
@@ -46,6 +49,10 @@ public function eof(): bool
4649
4750 public function getContents (): string
4851 {
52+ if ($ this ->isClosed ) {
53+ throw new \RuntimeException ("Stream is closed " );
54+ }
55+
4956 $ buffer = $ this ->buffer ;
5057 $ this ->buffer = '' ;
5158
@@ -69,7 +76,7 @@ public function getSize(): ?int
6976
7077 public function isReadable (): bool
7178 {
72- return !$ this ->eof () ;
79+ return !$ this ->isClosed ;
7380 }
7481
7582 public function isSeekable (): bool
@@ -84,7 +91,7 @@ public function isWritable(): bool
8491
8592 public function read (int $ length ): string
8693 {
87- if ($ this ->eof () ) {
94+ if ($ this ->isClosed ) {
8895 throw new \RuntimeException ("Stream is closed " );
8996 }
9097
Original file line number Diff line number Diff line change @@ -93,8 +93,7 @@ public function testTell(): void
9393 self ::assertSame ('' , $ requestStream ->read (8192 ));
9494 self ::assertSame (6 , $ requestStream ->tell ());
9595 self ::assertTrue ($ requestStream ->eof ());
96- self ::assertFalse ($ requestStream ->isReadable ());
97-
96+ self ::assertTrue ($ requestStream ->isReadable ());
9897 }
9998
10099 public function testRewindThrowsException (): void
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ public function testToPsrResponseReturnsResponseWithStreamableBody(): void
267267
268268 self ::assertSame ('content ' , $ body ->read (8192 ));
269269 self ::assertTrue ($ body ->eof ());
270- self ::assertFalse ($ body ->isReadable ());
270+ self ::assertTrue ($ body ->isReadable ());
271271 }
272272
273273 public function testFromPsrResponseWithRequestReturnsResultWithSameRequest (): void
You can’t perform that action at this time.
0 commit comments