Skip to content

Commit

Permalink
Merge pull request #165 from clue-labs/php8.2
Browse files Browse the repository at this point in the history
Make tests compatible with PHP 8.2 by avoiding dynamic properties
  • Loading branch information
WyriHaximus committed Jun 24, 2022
2 parents c7af3d8 + f96bfb2 commit 68c2121
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/EnforceBlockingWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions tests/WritableResourceStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

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

0 comments on commit 68c2121

Please sign in to comment.