diff --git a/tests/EnforceBlockingWrapper.php b/tests/EnforceBlockingWrapper.php index 39c0487..a171b41 100644 --- a/tests/EnforceBlockingWrapper.php +++ b/tests/EnforceBlockingWrapper.php @@ -5,10 +5,12 @@ /** * Used to test dummy stream resources that do not support setting non-blocking mode * - * @link http://php.net/manual/de/class.streamwrapper.php + * @link https://www.php.net/manual/en/class.streamwrapper.php */ class EnforceBlockingWrapper { + public $context; + public function stream_open($path, $mode, $options, &$opened_path) { return true; diff --git a/tests/WritableResourceStreamTest.php b/tests/WritableResourceStreamTest.php index 38d4259..678db98 100644 --- a/tests/WritableResourceStreamTest.php +++ b/tests/WritableResourceStreamTest.php @@ -157,14 +157,23 @@ public function testEmptyWriteDoesNotAddToLoop() public function testWriteReturnsFalseWhenWritableResourceStreamIsFull() { $stream = fopen('php://temp', 'r+'); - $loop = $this->createWriteableLoopMock(); - $loop->preventWrites = true; + + $preventWrites = true; + $loop = $this->createLoopMock(); + $loop + ->expects($this->any()) + ->method('addWriteStream') + ->will($this->returnCallback(function ($stream, $listener) use (&$preventWrites) { + if (!$preventWrites) { + call_user_func($listener, $stream); + } + })); $buffer = new WritableResourceStream($stream, $loop, 4); $buffer->on('error', $this->expectCallableNever()); $this->assertTrue($buffer->write("foo")); - $loop->preventWrites = false; + $preventWrites = false; $this->assertFalse($buffer->write("bar\n")); } @@ -504,14 +513,11 @@ public function testWritingToClosedStream() private function createWriteableLoopMock() { $loop = $this->createLoopMock(); - $loop->preventWrites = false; $loop ->expects($this->any()) ->method('addWriteStream') - ->will($this->returnCallback(function ($stream, $listener) use ($loop) { - if (!$loop->preventWrites) { - call_user_func($listener, $stream); - } + ->will($this->returnCallback(function ($stream, $listener) { + call_user_func($listener, $stream); })); return $loop;