File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,22 @@ public function __construct(
31
31
$ this ->unwrap ();
32
32
}
33
33
34
+ /**
35
+ * @param mixed $resource
36
+ *
37
+ * @psalm-assert resource $resource
38
+ *
39
+ * @throws RuntimeException
40
+ */
41
+ public static function parse (mixed $ resource ): self
42
+ {
43
+ if (!is_resource ($ resource )) {
44
+ throw ResourceStreamException::noResource ();
45
+ }
46
+
47
+ return new self ($ resource );
48
+ }
49
+
34
50
public function __destruct ()
35
51
{
36
52
if (!$ this ->keepAlive ) {
Original file line number Diff line number Diff line change @@ -24,6 +24,22 @@ public function it_detects_closed_streams_during_construction(): void
24
24
new ResourceStream ($ f );
25
25
}
26
26
27
+ #[Test]
28
+ public function it_can_parse_a_valid_stream (): void
29
+ {
30
+ $ f = fopen ('php://memory ' , 'r ' );
31
+ $ resourceStream = ResourceStream::parse ($ f );
32
+
33
+ self ::assertSame ($ f , $ resourceStream ->unwrap ());
34
+ }
35
+
36
+ #[Test]
37
+ public function it_can_parse_a_mixed_value_to_be_a_stream (): void
38
+ {
39
+ $ this ->expectException (ResourceStreamException::class);
40
+ ResourceStream::parse ('no-stream ' );
41
+ }
42
+
27
43
#[Test]
28
44
public function it_can_unwrap_a_stream (): void
29
45
{
You can’t perform that action at this time.
0 commit comments