@@ -47,6 +47,15 @@ protected function tearDown(): void
4747 }
4848 }
4949
50+ protected function setAccessible (ReflectionProperty $ property , bool $ accessible = true ): void
51+ {
52+ // only if PHP version < 8.1
53+ if (PHP_VERSION_ID > 80100 ) {
54+ return ;
55+ }
56+ $ property ->setAccessible ($ accessible );
57+ }
58+
5059 /**
5160 * @param string $mode
5261 *
@@ -66,7 +75,7 @@ public function testConstructorAttachesStream()
6675 $ this ->stream = $ this ->resourceFactory ();
6776 $ body = new Stream ($ this ->stream );
6877 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
69- $ bodyStream ->setAccessible (true );
78+ $ this ->setAccessible ($ bodyStream );
7079
7180 $ this ->assertSame ($ this ->stream , $ bodyStream ->getValue ($ body ));
7281 }
@@ -109,19 +118,19 @@ public function testDetach()
109118 $ body = new Stream ($ this ->stream );
110119
111120 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
112- $ bodyStream ->setAccessible (true );
121+ $ this ->setAccessible ($ bodyStream );
113122
114123 $ bodyMetadata = new ReflectionProperty ($ body , 'meta ' );
115- $ bodyMetadata ->setAccessible (true );
124+ $ this ->setAccessible ($ bodyMetadata );
116125
117126 $ bodyReadable = new ReflectionProperty ($ body , 'readable ' );
118- $ bodyReadable ->setAccessible (true );
127+ $ this ->setAccessible ($ bodyReadable );
119128
120129 $ bodyWritable = new ReflectionProperty ($ body , 'writable ' );
121- $ bodyWritable ->setAccessible (true );
130+ $ this ->setAccessible ($ bodyWritable );
122131
123132 $ bodySeekable = new ReflectionProperty ($ body , 'seekable ' );
124- $ bodySeekable ->setAccessible (true );
133+ $ this ->setAccessible ($ bodySeekable );
125134
126135 $ result = $ body ->detach ();
127136
@@ -156,7 +165,7 @@ public function testToStringDetached()
156165 $ this ->stream = $ this ->resourceFactory ();
157166 $ body = new Stream ($ this ->stream );
158167 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
159- $ bodyStream ->setAccessible (true );
168+ $ this ->setAccessible ($ bodyStream );
160169 $ bodyStream ->setValue ($ body , null );
161170
162171 $ this ->assertEquals ('' , (string ) $ body );
@@ -169,7 +178,7 @@ public function testClose()
169178 $ body ->close ();
170179
171180 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
172- $ bodyStream ->setAccessible (true );
181+ $ this ->setAccessible ($ bodyStream );
173182
174183 $ this ->assertNull ($ bodyStream ->getValue ($ body ));
175184 }
@@ -187,7 +196,7 @@ public function testGetSizeDetached()
187196 $ this ->stream = $ this ->resourceFactory ();
188197 $ body = new Stream ($ this ->stream );
189198 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
190- $ bodyStream ->setAccessible (true );
199+ $ this ->setAccessible ($ bodyStream );
191200 $ bodyStream ->setValue ($ body , null );
192201
193202 $ this ->assertNull ($ body ->getSize ());
@@ -209,7 +218,7 @@ public function testTellDetachedThrowsRuntimeException()
209218 $ this ->stream = $ this ->resourceFactory ();
210219 $ body = new Stream ($ this ->stream );
211220 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
212- $ bodyStream ->setAccessible (true );
221+ $ this ->setAccessible ($ bodyStream );
213222 $ bodyStream ->setValue ($ body , null );
214223
215224 $ body ->tell ();
@@ -240,7 +249,7 @@ public function testEofDetached()
240249 $ this ->stream = $ this ->resourceFactory ();
241250 $ body = new Stream ($ this ->stream );
242251 $ bodyStream = new ReflectionProperty ($ body , 'stream ' );
243- $ bodyStream ->setAccessible (true );
252+ $ this ->setAccessible ($ bodyStream );
244253 $ bodyStream ->setValue ($ body , null );
245254
246255 $ this ->assertTrue ($ body ->eof ());
0 commit comments