-
-
Save clue/7e6012fecc995dee201eb3aae600bcfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/01-http.php b/examples/01-http.php | |
index e70691d..786aefc 100644 | |
--- a/examples/01-http.php | |
+++ b/examples/01-http.php | |
@@ -15,7 +15,7 @@ | |
require __DIR__ . '/../vendor/autoload.php'; | |
-$host = isset($argv[1]) ? $argv[1] : 'www.google.com'; | |
+$host = $argv[1] ?? 'www.google.com'; | |
// connect to tcp://www.google.com:80 (blocking call!) | |
// for illustration purposes only, should use react/http-client or react/socket instead! | |
diff --git a/examples/02-https.php b/examples/02-https.php | |
index 1d212da..e629791 100644 | |
--- a/examples/02-https.php | |
+++ b/examples/02-https.php | |
@@ -15,7 +15,7 @@ | |
require __DIR__ . '/../vendor/autoload.php'; | |
-$host = isset($argv[1]) ? $argv[1] : 'www.google.com'; | |
+$host = $argv[1] ?? 'www.google.com'; | |
// connect to tls://www.google.com:443 (blocking call!) | |
// for illustration purposes only, should use react/http-client or react/socket instead! | |
diff --git a/examples/91-benchmark-throughput.php b/examples/91-benchmark-throughput.php | |
index 4203950..c396606 100644 | |
--- a/examples/91-benchmark-throughput.php | |
+++ b/examples/91-benchmark-throughput.php | |
@@ -21,9 +21,9 @@ | |
} | |
$args = getopt('i:o:t:'); | |
-$if = isset($args['i']) ? $args['i'] : '/dev/zero'; | |
-$of = isset($args['o']) ? $args['o'] : '/dev/null'; | |
-$t = isset($args['t']) ? $args['t'] : 1; | |
+$if = $args['i'] ?? '/dev/zero'; | |
+$of = $args['o'] ?? '/dev/null'; | |
+$t = $args['t'] ?? 1; | |
// passing file descriptors requires mapping paths (https://bugs.php.net/bug.php?id=53465) | |
$if = str_replace('/dev/fd/', 'php://fd/', $if); | |
diff --git a/src/DuplexResourceStream.php b/src/DuplexResourceStream.php | |
index ed4dbe0..0b52c9b 100644 | |
--- a/src/DuplexResourceStream.php | |
+++ b/src/DuplexResourceStream.php | |
@@ -46,7 +46,7 @@ | |
// ensure resource is opened for reading and wrting (fopen mode must contain "+") | |
$meta = \stream_get_meta_data($stream); | |
- if (isset($meta['mode']) && $meta['mode'] !== '' && \strpos($meta['mode'], '+') === false) { | |
+ if (\strpos($meta['mode'], '+') === false) { | |
throw new InvalidArgumentException('Given stream resource is not opened in read and write mode'); | |
} | |
@@ -106,9 +106,7 @@ | |
public function resume() | |
{ | |
if (!$this->listening && $this->readable) { | |
- $this->loop->addReadStream($this->stream, function () { | |
- $this->handleData(); | |
- }); | |
+ $this->loop->addReadStream($this->stream, [$this, 'handleData']); | |
$this->listening = true; | |
} | |
} | |
@@ -163,7 +161,8 @@ | |
return Util::pipe($this, $dest, $options); | |
} | |
- private function handleData() | |
+ /** @internal */ | |
+ public function handleData($stream) | |
{ | |
$error = null; | |
\set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$error) { | |
@@ -176,7 +175,7 @@ | |
); | |
}); | |
- $data = \stream_get_contents($this->stream, $this->bufferSize); | |
+ $data = \stream_get_contents($stream, $this->bufferSize); | |
\restore_error_handler(); | |
diff --git a/src/ReadableResourceStream.php b/src/ReadableResourceStream.php | |
index 8b66aab..41314fe 100644 | |
--- a/src/ReadableResourceStream.php | |
+++ b/src/ReadableResourceStream.php | |
@@ -48,7 +48,7 @@ | |
// ensure resource is opened for reading (fopen mode must contain "r" or "+") | |
$meta = \stream_get_meta_data($stream); | |
- if (isset($meta['mode']) && $meta['mode'] !== '' && \strpos($meta['mode'], 'r') === \strpos($meta['mode'], '+')) { | |
+ if (\strpos($meta['mode'], 'r') === \strpos($meta['mode'], '+')) { | |
throw new InvalidArgumentException('Given stream resource is not opened in read mode'); | |
} | |
@@ -88,9 +88,7 @@ | |
public function resume() | |
{ | |
if (!$this->listening && !$this->closed) { | |
- $this->loop->addReadStream($this->stream, function () { | |
- $this->handleData(); | |
- }); | |
+ $this->loop->addReadStream($this->stream, [$this, 'handleData']); | |
$this->listening = true; | |
} | |
} | |
@@ -117,7 +115,8 @@ | |
} | |
} | |
- private function handleData() | |
+ /** @internal */ | |
+ public function handleData() | |
{ | |
$error = null; | |
\set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$error) { | |
diff --git a/src/WritableResourceStream.php b/src/WritableResourceStream.php | |
index a091e29..9665721 100644 | |
--- a/src/WritableResourceStream.php | |
+++ b/src/WritableResourceStream.php | |
@@ -36,7 +36,7 @@ | |
// ensure resource is opened for writing (fopen mode must contain either of "waxc+") | |
$meta = \stream_get_meta_data($stream); | |
- if (isset($meta['mode']) && $meta['mode'] !== '' && \strtr($meta['mode'], 'waxc+', '.....') === $meta['mode']) { | |
+ if (\strtr($meta['mode'], 'waxc+', '.....') === $meta['mode']) { | |
throw new \InvalidArgumentException('Given stream resource is not opened in write mode'); | |
} | |
@@ -68,9 +68,7 @@ | |
if (!$this->listening && $this->data !== '') { | |
$this->listening = true; | |
- $this->loop->addWriteStream($this->stream, function () { | |
- $this->handleWrite(); | |
- }); | |
+ $this->loop->addWriteStream($this->stream, [$this, 'handleWrite']); | |
} | |
return !isset($this->data[$this->softLimit - 1]); | |
@@ -114,6 +112,7 @@ | |
} | |
} | |
+ /** @internal */ | |
public function handleWrite() | |
{ | |
$error = null; | |
diff --git a/tests/CompositeStreamTest.php b/tests/CompositeStreamTest.php | |
index c858e6b..75a0426 100644 | |
--- a/tests/CompositeStreamTest.php | |
+++ b/tests/CompositeStreamTest.php | |
@@ -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 | |
@@ -13,7 +15,7 @@ | |
/** @test */ | |
public function itShouldCloseReadableIfNotWritable() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->once()) | |
->method('isReadable') | |
@@ -22,7 +24,7 @@ | |
->expects($this->once()) | |
->method('close'); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->once()) | |
->method('isWritable') | |
@@ -37,13 +39,13 @@ | |
/** @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'); | |
@@ -57,13 +59,13 @@ | |
/** @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') | |
@@ -81,7 +83,7 @@ | |
/** @test */ | |
public function itShouldForwardReadableCallsToReadableStream() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->exactly(2)) | |
->method('isReadable') | |
@@ -93,7 +95,7 @@ | |
->expects($this->once()) | |
->method('resume'); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -108,7 +110,7 @@ | |
/** @test */ | |
public function itShouldNotForwardResumeIfStreamIsNotWritable() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->once()) | |
->method('isReadable') | |
@@ -117,7 +119,7 @@ | |
->expects($this->never()) | |
->method('resume'); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->exactly(2)) | |
->method('isWritable') | |
@@ -130,13 +132,13 @@ | |
/** @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') | |
@@ -153,7 +155,7 @@ | |
/** @test */ | |
public function closeShouldCloseBothStreams() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->once()) | |
->method('isReadable') | |
@@ -162,7 +164,7 @@ | |
->expects($this->once()) | |
->method('close'); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->once()) | |
->method('isWritable') | |
@@ -224,13 +226,13 @@ | |
/** @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()) | |
@@ -249,12 +251,12 @@ | |
{ | |
$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()) | |
diff --git a/tests/DuplexResourceStreamIntegrationTest.php b/tests/DuplexResourceStreamIntegrationTest.php | |
index ef4d3c4..02da5d2 100644 | |
--- a/tests/DuplexResourceStreamIntegrationTest.php | |
+++ b/tests/DuplexResourceStreamIntegrationTest.php | |
@@ -2,14 +2,12 @@ | |
namespace React\Tests\Stream; | |
-use Clue\StreamFilter as Filter; | |
use React\Stream\DuplexResourceStream; | |
use React\Stream\ReadableResourceStream; | |
use React\EventLoop\ExtEventLoop; | |
-use React\EventLoop\ExtEvLoop; | |
-use React\EventLoop\ExtUvLoop; | |
use React\EventLoop\LoopInterface; | |
use React\EventLoop\StreamSelectLoop; | |
+use function Clue\StreamFilter\append as filter_append; | |
class DuplexResourceStreamIntegrationTest extends TestCase | |
{ | |
@@ -25,23 +23,7 @@ | |
]; | |
yield [ | |
function () { | |
- return class_exists('EvLoop'); | |
- }, | |
- function () { | |
- return new ExtEvLoop(); | |
- } | |
- ]; | |
- yield [ | |
- function () { | |
- return \function_exists('uv_loop_new'); | |
- }, | |
- function () { | |
- return new ExtUvLoop(); | |
- } | |
- ]; | |
- yield [ | |
- function () { | |
- return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop'); | |
+ return class_exists('EventBase'); | |
}, | |
function () { | |
return new ExtEventLoop(); | |
@@ -356,7 +338,7 @@ | |
// add a filter which returns an error when encountering an 'a' when reading | |
- Filter\append($stream, function ($chunk) { | |
+ filter_append($stream, function ($chunk) { | |
return ''; | |
}, STREAM_FILTER_READ); | |
@@ -369,10 +351,7 @@ | |
fwrite($client, "foobar\n"); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
fclose($stream); | |
fclose($client); | |
diff --git a/tests/DuplexResourceStreamTest.php b/tests/DuplexResourceStreamTest.php | |
index 4b0de94..52477fe 100644 | |
--- a/tests/DuplexResourceStreamTest.php | |
+++ b/tests/DuplexResourceStreamTest.php | |
@@ -2,9 +2,11 @@ | |
namespace React\Tests\Stream; | |
+use React\EventLoop\LoopInterface; | |
use React\Stream\DuplexResourceStream; | |
-use Clue\StreamFilter as Filter; | |
use React\Stream\WritableResourceStream; | |
+use React\Stream\WritableStreamInterface; | |
+use function Clue\StreamFilter\append as filter_append; | |
class DuplexResourceStreamTest extends TestCase | |
{ | |
@@ -56,7 +58,7 @@ | |
{ | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new DuplexResourceStream('breakme', $loop); | |
} | |
@@ -67,7 +69,7 @@ | |
{ | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new DuplexResourceStream(STDOUT, $loop); | |
} | |
@@ -82,7 +84,7 @@ | |
unlink($name); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new DuplexResourceStream($stream, $loop); | |
} | |
@@ -98,7 +100,7 @@ | |
$stream = fopen('blocking://test', 'r+'); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('RunTimeException'); | |
+ $this->expectException(\RuntimeException::class); | |
new DuplexResourceStream($stream, $loop); | |
} | |
@@ -111,7 +113,7 @@ | |
$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); | |
} | |
@@ -130,7 +132,7 @@ | |
$buffer = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
- $this->expectException('RunTimeException'); | |
+ $this->expectException(\RuntimeException::class); | |
new DuplexResourceStream($stream, $loop, null, $buffer); | |
} | |
@@ -153,7 +155,7 @@ | |
$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); | |
@@ -166,7 +168,7 @@ | |
$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); | |
@@ -193,10 +195,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertSame("foobar\n", $capturedData); | |
} | |
@@ -219,10 +218,7 @@ | |
fwrite($stream, str_repeat("a", 100000)); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertTrue($conn->isReadable()); | |
$this->assertEquals(4321, strlen($capturedData)); | |
@@ -248,10 +244,7 @@ | |
fwrite($stream, str_repeat("a", 100000)); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertTrue($conn->isReadable()); | |
$this->assertEquals(100000, strlen($capturedData)); | |
@@ -268,10 +261,7 @@ | |
$conn = new DuplexResourceStream($stream, $loop); | |
$conn->on('data', $this->expectCallableNever()); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
/** | |
@@ -418,7 +408,7 @@ | |
$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)); | |
} | |
@@ -455,10 +445,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
/** | |
@@ -469,7 +456,7 @@ | |
$stream = fopen('php://temp', 'r+'); | |
// add a filter which removes every 'a' when reading | |
- Filter\append($stream, function ($chunk) { | |
+ filter_append($stream, function ($chunk) { | |
return str_replace('a', '', $chunk); | |
}, STREAM_FILTER_READ); | |
@@ -485,10 +472,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertSame("foobr\n", $capturedData); | |
} | |
@@ -500,7 +484,7 @@ | |
$stream = fopen('php://temp', 'r+'); | |
// add a filter which returns an error when encountering an 'a' when reading | |
- Filter\append($stream, function ($chunk) { | |
+ filter_append($stream, function ($chunk) { | |
if (strpos($chunk, 'a') !== false) { | |
throw new \Exception('Invalid'); | |
} | |
@@ -517,10 +501,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
private function createWriteableLoopMock() | |
@@ -538,6 +519,6 @@ | |
private function createLoopMock() | |
{ | |
- return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); | |
+ return $this->createMock(LoopInterface::class); | |
} | |
} | |
diff --git a/tests/ReadableResourceStreamTest.php b/tests/ReadableResourceStreamTest.php | |
index f14c667..4cebb5a 100644 | |
--- a/tests/ReadableResourceStreamTest.php | |
+++ b/tests/ReadableResourceStreamTest.php | |
@@ -2,8 +2,10 @@ | |
namespace React\Tests\Stream; | |
+use React\EventLoop\LoopInterface; | |
use React\Stream\ReadableResourceStream; | |
-use Clue\StreamFilter as Filter; | |
+use React\Stream\WritableStreamInterface; | |
+use function Clue\StreamFilter\append as filter_append; | |
class ReadableResourceStreamTest extends TestCase | |
{ | |
@@ -55,7 +57,7 @@ | |
{ | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new ReadableResourceStream(false, $loop); | |
} | |
@@ -66,7 +68,7 @@ | |
{ | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new ReadableResourceStream(STDOUT, $loop); | |
} | |
@@ -81,7 +83,7 @@ | |
unlink($name); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new ReadableResourceStream($stream, $loop); | |
} | |
@@ -97,7 +99,7 @@ | |
$stream = fopen('blocking://test', 'r+'); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('RuntimeException'); | |
+ $this->expectException(\RuntimeException::class); | |
new ReadableResourceStream($stream, $loop); | |
} | |
@@ -146,10 +148,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertSame("foobar\n", $capturedData); | |
} | |
@@ -172,10 +171,7 @@ | |
fwrite($stream, str_repeat("a", 100000)); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertTrue($conn->isReadable()); | |
$this->assertEquals(4321, strlen($capturedData)); | |
@@ -201,10 +197,7 @@ | |
fwrite($stream, str_repeat("a", 100000)); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertTrue($conn->isReadable()); | |
$this->assertEquals(100000, strlen($capturedData)); | |
@@ -221,10 +214,7 @@ | |
$conn = new ReadableResourceStream($stream, $loop); | |
$conn->on('data', $this->expectCallableNever()); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
public function testPipeShouldReturnDestination() | |
@@ -233,7 +223,7 @@ | |
$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)); | |
} | |
@@ -255,10 +245,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
/** | |
@@ -341,7 +328,7 @@ | |
$stream = fopen('php://temp', 'r+'); | |
// add a filter which removes every 'a' when reading | |
- Filter\append($stream, function ($chunk) { | |
+ filter_append($stream, function ($chunk) { | |
return str_replace('a', '', $chunk); | |
}, STREAM_FILTER_READ); | |
@@ -357,10 +344,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
$this->assertSame("foobr\n", $capturedData); | |
} | |
@@ -372,7 +356,7 @@ | |
$stream = fopen('php://temp', 'r+'); | |
// add a filter which returns an error when encountering an 'a' when reading | |
- Filter\append($stream, function ($chunk) { | |
+ filter_append($stream, function ($chunk) { | |
if (strpos($chunk, 'a') !== false) { | |
throw new \Exception('Invalid'); | |
} | |
@@ -389,10 +373,7 @@ | |
fwrite($stream, "foobar\n"); | |
rewind($stream); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
- | |
+ $conn->handleData($stream); | |
} | |
/** | |
@@ -408,9 +389,7 @@ | |
$conn->on('data', $this->expectCallableNever()); | |
$conn->on('end', $this->expectCallableNever()); | |
- $ref = new \ReflectionMethod($conn, 'handleData'); | |
- $ref->setAccessible(true); | |
- $ref->invoke($conn, 'handleData'); | |
+ $conn->handleData(); | |
fclose($stream); | |
fclose($_); | |
@@ -418,6 +397,6 @@ | |
private function createLoopMock() | |
{ | |
- return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); | |
+ return $this->createMock(LoopInterface::class); | |
} | |
} | |
diff --git a/tests/ThroughStreamTest.php b/tests/ThroughStreamTest.php | |
index 7983a76..287ab9e 100644 | |
--- a/tests/ThroughStreamTest.php | |
+++ b/tests/ThroughStreamTest.php | |
@@ -3,6 +3,7 @@ | |
namespace React\Tests\Stream; | |
use React\Stream\ThroughStream; | |
+use React\Stream\WritableStreamInterface; | |
/** | |
* @covers React\Stream\ThroughStream | |
@@ -311,7 +312,7 @@ | |
/** @test */ | |
public function pipeShouldPipeCorrectly() | |
{ | |
- $output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $output = $this->createMock(WritableStreamInterface::class); | |
$output->expects($this->any())->method('isWritable')->willReturn(True); | |
$output | |
->expects($this->once()) | |
diff --git a/tests/UtilTest.php b/tests/UtilTest.php | |
index 47d3646..50b2e75 100644 | |
--- a/tests/UtilTest.php | |
+++ b/tests/UtilTest.php | |
@@ -2,10 +2,13 @@ | |
namespace React\Tests\Stream; | |
-use React\Stream\WritableResourceStream; | |
-use React\Stream\Util; | |
+use React\EventLoop\LoopInterface; | |
use React\Stream\CompositeStream; | |
+use React\Stream\ReadableStreamInterface; | |
use React\Stream\ThroughStream; | |
+use React\Stream\Util; | |
+use React\Stream\WritableResourceStream; | |
+use React\Stream\WritableStreamInterface; | |
/** | |
* @covers React\Stream\Util | |
@@ -14,9 +17,9 @@ | |
{ | |
public function testPipeReturnsDestinationStream() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$ret = Util::pipe($readable, $writable); | |
@@ -25,13 +28,13 @@ | |
public function testPipeNonReadableSourceShouldDoNothing() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->any()) | |
->method('isReadable') | |
->willReturn(false); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->never()) | |
->method('isWritable'); | |
@@ -44,7 +47,7 @@ | |
public function testPipeIntoNonWritableDestinationShouldPauseSource() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->any()) | |
->method('isReadable') | |
@@ -53,7 +56,7 @@ | |
->expects($this->once()) | |
->method('pause'); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -67,7 +70,7 @@ | |
public function testPipeClosingDestPausesSource() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable | |
->expects($this->any()) | |
->method('isReadable') | |
@@ -87,7 +90,7 @@ | |
{ | |
$readable = new Stub\ReadableStreamStub(); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -105,7 +108,7 @@ | |
{ | |
$readable = new Stub\ReadableStreamStub(); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -123,7 +126,7 @@ | |
{ | |
$readable = new Stub\ReadableStreamStub(); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -147,7 +150,7 @@ | |
$onDrain = null; | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable | |
->expects($this->any()) | |
->method('isWritable') | |
@@ -175,7 +178,7 @@ | |
$readable = new Stub\ReadableStreamStub(); | |
$stream = fopen('php://temp', 'r+'); | |
- $loop = $this->createLoopMock(); | |
+ $loop = $this->createMock(LoopInterface::class); | |
$buffer = new WritableResourceStream($stream, $loop); | |
$readable->pipe($buffer); | |
@@ -234,9 +237,9 @@ | |
public function testPipeDuplexIntoSelfEndsOnEnd() | |
{ | |
- $readable = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); | |
+ $readable = $this->createMock(ReadableStreamInterface::class); | |
$readable->expects($this->any())->method('isReadable')->willReturn(true); | |
- $writable = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); | |
+ $writable = $this->createMock(WritableStreamInterface::class); | |
$writable->expects($this->any())->method('isWritable')->willReturn(true); | |
$duplex = new CompositeStream($readable, $writable); | |
@@ -260,9 +263,4 @@ | |
$source->emit('data', ['hello']); | |
$source->emit('foo', ['bar']); | |
} | |
- | |
- private function createLoopMock() | |
- { | |
- return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); | |
- } | |
} | |
diff --git a/tests/WritableResourceStreamTest.php b/tests/WritableResourceStreamTest.php | |
index 89f4fc5..02f2367 100644 | |
--- a/tests/WritableResourceStreamTest.php | |
+++ b/tests/WritableResourceStreamTest.php | |
@@ -2,8 +2,9 @@ | |
namespace React\Tests\Stream; | |
-use Clue\StreamFilter as Filter; | |
+use React\EventLoop\LoopInterface; | |
use React\Stream\WritableResourceStream; | |
+use function Clue\StreamFilter\append as filter_append; | |
class WritableResourceStreamTest extends TestCase | |
{ | |
@@ -56,7 +57,7 @@ | |
$stream = null; | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new WritableResourceStream($stream, $loop); | |
} | |
@@ -68,7 +69,7 @@ | |
$stream = fopen('php://temp', 'r'); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new WritableResourceStream($stream, $loop); | |
} | |
@@ -83,7 +84,7 @@ | |
unlink($name); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('InvalidArgumentException'); | |
+ $this->expectException(\InvalidArgumentException::class); | |
new WritableResourceStream($stream, $loop); | |
} | |
@@ -99,7 +100,7 @@ | |
$stream = fopen('blocking://test', 'r+'); | |
$loop = $this->createLoopMock(); | |
- $this->expectException('RuntimeException'); | |
+ $this->expectException(\RuntimeException::class); | |
new WritableResourceStream($stream, $loop); | |
} | |
@@ -355,7 +356,7 @@ | |
$buffer->on('error', $this->expectCallableNever()); | |
$buffer->on('close', $this->expectCallableOnce()); | |
- Filter\append($stream, function ($chunk) use (&$filterBuffer) { | |
+ filter_append($stream, function ($chunk) use (&$filterBuffer) { | |
$filterBuffer .= $chunk; | |
return $chunk; | |
}); | |
@@ -466,7 +467,7 @@ | |
$buffer = new WritableResourceStream($stream, $loop); | |
- Filter\append($stream, function ($chunk) use (&$filterBuffer) { | |
+ filter_append($stream, function ($chunk) use (&$filterBuffer) { | |
$filterBuffer .= $chunk; | |
return $chunk; | |
}); | |
@@ -502,7 +503,7 @@ | |
$buffer->write('bar'); | |
$buffer->handleWrite(); | |
- $this->assertInstanceOf('Exception', $error); | |
+ $this->assertInstanceOf(\Exception::class, $error); | |
$this->assertEqualsIgnoringCase('Unable to write to stream: fwrite(): send of 3 bytes failed with errno=32 Broken pipe', $error->getMessage()); | |
} | |
@@ -521,6 +522,6 @@ | |
private function createLoopMock() | |
{ | |
- return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); | |
+ return $this->createMock(LoopInterface::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment