diff --git a/tests/StreamTest.php b/tests/StreamTest.php index c41e8a2..eaf325f 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -10,6 +10,9 @@ namespace Slim\Tests\Psr7; use PHPUnit\Framework\TestCase; +use ReflectionException; +use ReflectionMethod; +use ReflectionProperty; use RuntimeException; use Slim\Psr7\Stream; @@ -126,6 +129,32 @@ public function testPipeGetContents() $this->assertSame('12', $contents); } + /** + * Test that a call to the protected method `attach` would invoke `detach`. + * + * @throws ReflectionException + */ + public function testAttachAgain() + { + $this->openPipeStream(); + + $streamProphecy = $this->prophesize(Stream::class); + + /** @noinspection PhpUndefinedMethodInspection */ + $streamProphecy->detach()->shouldBeCalled(); + + /** @var Stream $stream */ + $stream = $streamProphecy->reveal(); + + $streamProperty = new ReflectionProperty(Stream::class, 'stream'); + $streamProperty->setAccessible(true); + $streamProperty->setValue($stream, $this->pipeFh); + + $attachMethod = new ReflectionMethod(Stream::class, 'attach'); + $attachMethod->setAccessible(true); + $attachMethod->invoke($stream, $this->pipeFh); + } + private function openPipeStream() { $this->pipeFh = popen('echo 12', 'r');