Skip to content

Commit

Permalink
Add test case for protected attach method
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansuter committed May 3, 2019
1 parent 84c7a0a commit a39217d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
namespace Slim\Tests\Psr7;

use PHPUnit\Framework\TestCase;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use RuntimeException;
use Slim\Psr7\Stream;

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit a39217d

Please sign in to comment.