Skip to content

Commit

Permalink
Update test suite and remove legacy PHPUnit workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus authored and clue committed May 15, 2024
1 parent a06b914 commit 1bb9595
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 138 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7",
"phpunit/phpunit": "^9.6 || ^7.5",
"clue/stream-filter": "~1.2"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
38 changes: 20 additions & 18 deletions tests/CompositeStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace React\Tests\Stream;

use React\Stream\CompositeStream;
use React\Stream\ReadableStreamInterface;
use React\Stream\ThroughStream;
use React\Stream\WritableStreamInterface;

/**
* @covers React\Stream\CompositeStream
Expand All @@ -13,7 +15,7 @@ class CompositeStreamTest extends TestCase
/** @test */
public function itShouldCloseReadableIfNotWritable()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
Expand All @@ -22,7 +24,7 @@ public function itShouldCloseReadableIfNotWritable()
->expects($this->once())
->method('close');

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->once())
->method('isWritable')
Expand All @@ -37,13 +39,13 @@ public function itShouldCloseReadableIfNotWritable()
/** @test */
public function itShouldCloseWritableIfNotReadable()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
->willReturn(false);

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->once())
->method('close');
Expand All @@ -57,13 +59,13 @@ public function itShouldCloseWritableIfNotReadable()
/** @test */
public function itShouldForwardWritableCallsToWritableStream()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
->willReturn(true);

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->once())
->method('write')
Expand All @@ -81,7 +83,7 @@ public function itShouldForwardWritableCallsToWritableStream()
/** @test */
public function itShouldForwardReadableCallsToReadableStream()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->exactly(2))
->method('isReadable')
Expand All @@ -93,7 +95,7 @@ public function itShouldForwardReadableCallsToReadableStream()
->expects($this->once())
->method('resume');

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->any())
->method('isWritable')
Expand All @@ -108,7 +110,7 @@ public function itShouldForwardReadableCallsToReadableStream()
/** @test */
public function itShouldNotForwardResumeIfStreamIsNotWritable()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
Expand All @@ -117,7 +119,7 @@ public function itShouldNotForwardResumeIfStreamIsNotWritable()
->expects($this->never())
->method('resume');

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->exactly(2))
->method('isWritable')
Expand All @@ -130,13 +132,13 @@ public function itShouldNotForwardResumeIfStreamIsNotWritable()
/** @test */
public function endShouldDelegateToWritableWithData()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
->willReturn(true);

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->once())
->method('isWritable')
Expand All @@ -153,7 +155,7 @@ public function endShouldDelegateToWritableWithData()
/** @test */
public function closeShouldCloseBothStreams()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
Expand All @@ -162,7 +164,7 @@ public function closeShouldCloseBothStreams()
->expects($this->once())
->method('close');

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable
->expects($this->once())
->method('isWritable')
Expand Down Expand Up @@ -224,13 +226,13 @@ public function itShouldReceiveForwardedEvents()
/** @test */
public function itShouldHandlePipingCorrectly()
{
$readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$readable = $this->createMock(ReadableStreamInterface::class);
$readable
->expects($this->once())
->method('isReadable')
->willReturn(true);

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable->expects($this->any())->method('isWritable')->willReturn(True);
$writable
->expects($this->once())
Expand All @@ -249,12 +251,12 @@ public function itShouldForwardPipeCallsToReadableStream()
{
$readable = new ThroughStream();

$writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$writable = $this->createMock(WritableStreamInterface::class);
$writable->expects($this->any())->method('isWritable')->willReturn(True);

$composite = new CompositeStream($readable, $writable);

$output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$output = $this->createMock(WritableStreamInterface::class);
$output->expects($this->any())->method('isWritable')->willReturn(True);
$output
->expects($this->once())
Expand Down
34 changes: 16 additions & 18 deletions tests/DuplexResourceStreamIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ class DuplexResourceStreamIntegrationTest extends TestCase
{
public function loopProvider()
{
return array(
array(
function() {
return true;
},
function () {
return new StreamSelectLoop();
}
),
array(
function () {
return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop');
},
function () {
return new ExtEventLoop();
}
)
);
yield [
function() {
return true;
},
function () {
return new StreamSelectLoop();
}
];
yield [
function () {
return class_exists('EventBase');
},
function () {
return new ExtEventLoop();
}
];
}

/**
Expand Down
22 changes: 12 additions & 10 deletions tests/DuplexResourceStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace React\Tests\Stream;

use React\EventLoop\LoopInterface;
use React\Stream\DuplexResourceStream;
use React\Stream\WritableResourceStream;
use React\Stream\WritableStreamInterface;
use function Clue\StreamFilter\append as filter_append;

class DuplexResourceStreamTest extends TestCase
Expand Down Expand Up @@ -56,7 +58,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
{
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new DuplexResourceStream('breakme', $loop);
}

Expand All @@ -67,7 +69,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStream()
{
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new DuplexResourceStream(STDOUT, $loop);
}

Expand All @@ -82,7 +84,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
unlink($name);

$loop = $this->createLoopMock();
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new DuplexResourceStream($stream, $loop);
}

Expand All @@ -98,7 +100,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking(
$stream = fopen('blocking://test', 'r+');
$loop = $this->createLoopMock();

$this->setExpectedException('RunTimeException');
$this->expectException(\RuntimeException::class);
new DuplexResourceStream($stream, $loop);
}

Expand All @@ -111,7 +113,7 @@ public function testConstructorAcceptsBuffer()
$stream = fopen('php://temp', 'r+');
$loop = $this->createLoopMock();

$buffer = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$buffer = $this->createMock(WritableStreamInterface::class);

new DuplexResourceStream($stream, $loop, null, $buffer);
}
Expand All @@ -130,7 +132,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlockingW

$buffer = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();

$this->setExpectedException('RunTimeException');
$this->expectException(\RuntimeException::class);
new DuplexResourceStream($stream, $loop, null, $buffer);
}

Expand All @@ -153,7 +155,7 @@ public function testEndShouldEndBuffer()
$stream = fopen('php://temp', 'r+');
$loop = $this->createLoopMock();

$buffer = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$buffer = $this->createMock(WritableStreamInterface::class);
$buffer->expects($this->once())->method('end')->with('foo');

$conn = new DuplexResourceStream($stream, $loop, null, $buffer);
Expand All @@ -166,7 +168,7 @@ public function testEndAfterCloseIsNoOp()
$stream = fopen('php://temp', 'r+');
$loop = $this->createLoopMock();

$buffer = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$buffer = $this->createMock(WritableStreamInterface::class);
$buffer->expects($this->never())->method('end');

$conn = new DuplexResourceStream($stream, $loop);
Expand Down Expand Up @@ -406,7 +408,7 @@ public function testPipeShouldReturnDestination()
$loop = $this->createLoopMock();

$conn = new DuplexResourceStream($stream, $loop);
$dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$dest = $this->createMock(WritableStreamInterface::class);

$this->assertSame($dest, $conn->pipe($dest));
}
Expand Down Expand Up @@ -517,6 +519,6 @@ private function createWriteableLoopMock()

private function createLoopMock()
{
return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
return $this->createMock(LoopInterface::class);
}
}
14 changes: 8 additions & 6 deletions tests/ReadableResourceStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace React\Tests\Stream;

use React\EventLoop\LoopInterface;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableStreamInterface;
use function Clue\StreamFilter\append as filter_append;

class ReadableResourceStreamTest extends TestCase
Expand Down Expand Up @@ -55,7 +57,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
{
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new ReadableResourceStream(false, $loop);
}

Expand All @@ -66,7 +68,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStream()
{
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new ReadableResourceStream(STDOUT, $loop);
}

Expand All @@ -81,7 +83,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
unlink($name);

$loop = $this->createLoopMock();
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new ReadableResourceStream($stream, $loop);
}

Expand All @@ -97,7 +99,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking(
$stream = fopen('blocking://test', 'r+');
$loop = $this->createLoopMock();

$this->setExpectedException('RuntimeException');
$this->expectException(\RuntimeException::class);
new ReadableResourceStream($stream, $loop);
}

Expand Down Expand Up @@ -221,7 +223,7 @@ public function testPipeShouldReturnDestination()
$loop = $this->createLoopMock();

$conn = new ReadableResourceStream($stream, $loop);
$dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
$dest = $this->createMock(WritableStreamInterface::class);

$this->assertSame($dest, $conn->pipe($dest));
}
Expand Down Expand Up @@ -395,6 +397,6 @@ public function testEmptyReadShouldntFcloseStream()

private function createLoopMock()
{
return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
return $this->createMock(LoopInterface::class);
}
}
Loading

0 comments on commit 1bb9595

Please sign in to comment.