Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to require PHP 7.1+
Browse files Browse the repository at this point in the history
WyriHaximus committed Feb 23, 2024

Verified

This commit was signed with the committer’s verified signature.
WyriHaximus Cees-Jan Kiewiet
1 parent 751374f commit e4313ea
Showing 21 changed files with 109 additions and 258 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,11 +19,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
@@ -52,23 +47,3 @@ jobs:
- run: composer install
- run: vendor/bin/phpunit --coverage-text
- run: time php examples/91-benchmark-throughput.php

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar install
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm composer.phar install
- name: Run hhvm vendor/bin/phpunit
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm vendor/bin/phpunit
- name: Run time hhvm examples/91-benchmark-throughput.php
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: bash -c "time hhvm examples/91-benchmark-throughput.php"
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ By default, this will call `end()` on the destination stream once the
source stream emits an `end` event. This can be disabled like this:

```php
$source->pipe($dest, array('end' => false));
$source->pipe($dest, ['end' => false]);
```

Note that this only applies to the `end` event.
@@ -1126,7 +1126,7 @@ $through = new ThroughStream(function ($data) {
});
$through->on('data', $this->expectCallableOnceWith("[2, true]\n"));

$through->write(array(2, true));
$through->write([2, true]);
```

The callback function is allowed to throw an `Exception`. In this case,
@@ -1217,9 +1217,8 @@ composer require react/stream:^3@dev
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM.
It's *highly recommended to use PHP 7+* for this project due to its vast
performance improvements.
extensions and supports running on PHP 7.1 through current PHP 8+.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -26,12 +26,12 @@
}
],
"require": {
"php": ">=5.3.8",
"php": ">=7.1",
"react/event-loop": "^1.2",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"phpunit/phpunit": "^9.6 || ^7.5",
"clue/stream-filter": "~1.2"
},
"autoload": {
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -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/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
10 changes: 5 additions & 5 deletions src/CompositeStream.php
Original file line number Diff line number Diff line change
@@ -20,11 +20,11 @@ public function __construct(ReadableStreamInterface $readable, WritableStreamInt
return;
}

Util::forwardEvents($this->readable, $this, array('data', 'end', 'error'));
Util::forwardEvents($this->writable, $this, array('drain', 'error', 'pipe'));
Util::forwardEvents($this->readable, $this, ['data', 'end', 'error']);
Util::forwardEvents($this->writable, $this, ['drain', 'error', 'pipe']);

$this->readable->on('close', array($this, 'close'));
$this->writable->on('close', array($this, 'close'));
$this->readable->on('close', [$this, 'close']);
$this->writable->on('close', [$this, 'close']);
}

public function isReadable()
@@ -46,7 +46,7 @@ public function resume()
$this->readable->resume();
}

public function pipe(WritableStreamInterface $dest, array $options = array())
public function pipe(WritableStreamInterface $dest, array $options = [])
{
return Util::pipe($this, $dest, $options);
}
47 changes: 9 additions & 38 deletions src/DuplexResourceStream.php
Original file line number Diff line number Diff line change
@@ -59,14 +59,9 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
// Use unbuffered read operations on the underlying stream resource.
// Reading chunks from the stream may otherwise leave unread bytes in
// PHP's stream buffers which some event loop implementations do not
// trigger events on (edge triggered).
// This does not affect the default event loop implementation (level
// triggered), so we can ignore platforms not supporting this (HHVM).
// Pipe streams (such as STDIN) do not seem to require this and legacy
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
if (\function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
\stream_set_read_buffer($stream, 0);
}
// trigger events on (edge triggered). This does not affect the default
// event loop implementation (level triggered).
\stream_set_read_buffer($stream, 0);

if ($buffer === null) {
$buffer = new WritableResourceStream($stream, $loop);
@@ -80,10 +75,10 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
$that = $this;

$this->buffer->on('error', function ($error) use ($that) {
$that->emit('error', array($error));
$that->emit('error', [$error]);
});

$this->buffer->on('close', array($this, 'close'));
$this->buffer->on('close', [$this, 'close']);

$this->buffer->on('drain', function () use ($that) {
$that->emit('drain');
@@ -113,7 +108,7 @@ public function pause()
public function resume()
{
if (!$this->listening && $this->readable) {
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
$this->loop->addReadStream($this->stream, [$this, 'handleData']);
$this->listening = true;
}
}
@@ -163,7 +158,7 @@ public function end($data = null)
$this->buffer->end($data);
}

public function pipe(WritableStreamInterface $dest, array $options = array())
public function pipe(WritableStreamInterface $dest, array $options = [])
{
return Util::pipe($this, $dest, $options);
}
@@ -187,41 +182,17 @@ public function handleData($stream)
\restore_error_handler();

if ($error !== null) {
$this->emit('error', array(new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)));
$this->emit('error', [new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)]);
$this->close();
return;
}

if ($data !== '') {
$this->emit('data', array($data));
$this->emit('data', [$data]);
} elseif (\feof($this->stream)) {
// no data read => we reached the end and close the stream
$this->emit('end');
$this->close();
}
}

/**
* Returns whether this is a pipe resource in a legacy environment
*
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
* and PHP 5.5.12+ and newer.
*
* @param resource $resource
* @return bool
* @link https://github.com/reactphp/child-process/issues/40
*
* @codeCoverageIgnore
*/
private function isLegacyPipe($resource)
{
if (\PHP_VERSION_ID < 50428 || (\PHP_VERSION_ID >= 50500 && \PHP_VERSION_ID < 50512)) {
$meta = \stream_get_meta_data($resource);

if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {
return true;
}
}
return false;
}
}
43 changes: 7 additions & 36 deletions src/ReadableResourceStream.php
Original file line number Diff line number Diff line change
@@ -61,14 +61,9 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
// Use unbuffered read operations on the underlying stream resource.
// Reading chunks from the stream may otherwise leave unread bytes in
// PHP's stream buffers which some event loop implementations do not
// trigger events on (edge triggered).
// This does not affect the default event loop implementation (level
// triggered), so we can ignore platforms not supporting this (HHVM).
// Pipe streams (such as STDIN) do not seem to require this and legacy
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
if (\function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
\stream_set_read_buffer($stream, 0);
}
// trigger events on (edge triggered). This does not affect the default
// event loop implementation (level triggered).
\stream_set_read_buffer($stream, 0);

$this->stream = $stream;
$this->loop = $loop ?: Loop::get();
@@ -93,12 +88,12 @@ public function pause()
public function resume()
{
if (!$this->listening && !$this->closed) {
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
$this->loop->addReadStream($this->stream, [$this, 'handleData']);
$this->listening = true;
}
}

public function pipe(WritableStreamInterface $dest, array $options = array())
public function pipe(WritableStreamInterface $dest, array $options = [])
{
return Util::pipe($this, $dest, $options);
}
@@ -139,41 +134,17 @@ public function handleData()
\restore_error_handler();

if ($error !== null) {
$this->emit('error', array(new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)));
$this->emit('error', [new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)]);
$this->close();
return;
}

if ($data !== '') {
$this->emit('data', array($data));
$this->emit('data', [$data]);
} elseif (\feof($this->stream)) {
// no data read => we reached the end and close the stream
$this->emit('end');
$this->close();
}
}

/**
* Returns whether this is a pipe resource in a legacy environment
*
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
* and PHP 5.5.12+ and newer.
*
* @param resource $resource
* @return bool
* @link https://github.com/reactphp/child-process/issues/40
*
* @codeCoverageIgnore
*/
private function isLegacyPipe($resource)
{
if (\PHP_VERSION_ID < 50428 || (\PHP_VERSION_ID >= 50500 && \PHP_VERSION_ID < 50512)) {
$meta = \stream_get_meta_data($resource);

if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {
return true;
}
}
return false;
}
}
4 changes: 2 additions & 2 deletions src/ReadableStreamInterface.php
Original file line number Diff line number Diff line change
@@ -278,7 +278,7 @@ public function resume();
* source stream emits an `end` event. This can be disabled like this:
*
* ```php
* $source->pipe($dest, array('end' => false));
* $source->pipe($dest, ['end' => false]);
* ```
*
* Note that this only applies to the `end` event.
@@ -322,7 +322,7 @@ public function resume();
* @param array $options
* @return WritableStreamInterface $dest stream as-is
*/
public function pipe(WritableStreamInterface $dest, array $options = array());
public function pipe(WritableStreamInterface $dest, array $options = []);

/**
* Closes the stream (forcefully).
8 changes: 4 additions & 4 deletions src/ThroughStream.php
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
* });
* $through->on('data', $this->expectCallableOnceWith("[2, true]\n"));
*
* $through->write(array(2, true));
* $through->write([2, true]);
* ```
*
* The callback function is allowed to throw an `Exception`. In this case,
@@ -108,7 +108,7 @@ public function resume()
}
}

public function pipe(WritableStreamInterface $dest, array $options = array())
public function pipe(WritableStreamInterface $dest, array $options = [])
{
return Util::pipe($this, $dest, $options);
}
@@ -133,14 +133,14 @@ public function write($data)
try {
$data = \call_user_func($this->callback, $data);
} catch (\Exception $e) {
$this->emit('error', array($e));
$this->emit('error', [$e]);
$this->close();

return false;
}
}

$this->emit('data', array($data));
$this->emit('data', [$data]);

// emit drain event on next resume if currently paused (throttled)
if ($this->paused) {
4 changes: 2 additions & 2 deletions src/Util.php
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ final class Util
* @return WritableStreamInterface $dest stream as-is
* @see ReadableStreamInterface::pipe() for more details
*/
public static function pipe(ReadableStreamInterface $source, WritableStreamInterface $dest, array $options = array())
public static function pipe(ReadableStreamInterface $source, WritableStreamInterface $dest, array $options = [])
{
// source not readable => NO-OP
if (!$source->isReadable()) {
@@ -27,7 +27,7 @@ public static function pipe(ReadableStreamInterface $source, WritableStreamInter
return $dest;
}

$dest->emit('pipe', array($source));
$dest->emit('pipe', [$source]);

// forward all source data events as $dest->write()
$source->on('data', $dataer = function ($data) use ($source, $dest) {
4 changes: 2 additions & 2 deletions src/WritableResourceStream.php
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public function write($data)
if (!$this->listening && $this->data !== '') {
$this->listening = true;

$this->loop->addWriteStream($this->stream, array($this, 'handleWrite'));
$this->loop->addWriteStream($this->stream, [$this, 'handleWrite']);
}

return !isset($this->data[$this->softLimit - 1]);
@@ -137,7 +137,7 @@ public function handleWrite()
// Should this turn out to be a permanent error later, it will eventually
// send *nothing* and we can detect this.
if (($sent === 0 || $sent === false) && $error !== null) {
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . $error)));
$this->emit('error', [new \RuntimeException('Unable to write to stream: ' . $error)]);
$this->close();

return;
6 changes: 3 additions & 3 deletions tests/CompositeStreamTest.php
Original file line number Diff line number Diff line change
@@ -217,7 +217,7 @@ public function itShouldReceiveForwardedEvents()
$composite->on('data', $this->expectCallableOnce());
$composite->on('drain', $this->expectCallableOnce());

$readable->emit('data', array('foo'));
$readable->emit('data', ['foo']);
$writable->emit('drain');
}

@@ -241,7 +241,7 @@ public function itShouldHandlePipingCorrectly()

$input = new ThroughStream();
$input->pipe($composite);
$input->emit('data', array('foo'));
$input->emit('data', ['foo']);
}

/** @test */
@@ -262,6 +262,6 @@ public function itShouldForwardPipeCallsToReadableStream()
->with('foo');

$composite->pipe($output);
$readable->emit('data', array('foo'));
$readable->emit('data', ['foo']);
}
}
72 changes: 34 additions & 38 deletions tests/DuplexResourceStreamIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -6,51 +6,47 @@
use React\Stream\DuplexResourceStream;
use React\Stream\ReadableResourceStream;
use React\EventLoop\ExtEventLoop;
use React\EventLoop\ExtLibeventLoop;
use React\EventLoop\ExtLibevLoop;
use React\EventLoop\ExtEvLoop;
use React\EventLoop\ExtUvLoop;
use React\EventLoop\LoopInterface;
use React\EventLoop\LibEventLoop;
use React\EventLoop\LibEvLoop;
use React\EventLoop\StreamSelectLoop;

class DuplexResourceStreamIntegrationTest extends TestCase
{
public function loopProvider()
{
return array(
array(
function() {
return true;
},
function () {
return new StreamSelectLoop();
}
),
array(
function () {
return function_exists('event_base_new');
},
function () {
return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : new LibEventLoop();
}
),
array(
function () {
return class_exists('libev\EventLoop');
},
function () {
return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
}
),
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('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');
},
function () {
return new ExtEventLoop();
}
];
}

/**
16 changes: 6 additions & 10 deletions tests/DuplexResourceStreamTest.php
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
{
$loop = $this->createLoopMock();

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

@@ -65,13 +65,9 @@ public function testConstructorThrowsExceptionOnInvalidStream()
*/
public function testConstructorThrowsExceptionOnWriteOnlyStream()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not report fopen mode for STDOUT');
}

$loop = $this->createLoopMock();

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

@@ -86,7 +82,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
unlink($name);

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

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

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

@@ -134,7 +130,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlockingW

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

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

@@ -427,7 +423,7 @@ public function testBufferEventsShouldBubbleUp()
$conn->on('error', $this->expectCallableOnce());

$buffer->emit('drain');
$buffer->emit('error', array(new \RuntimeException('Whoops')));
$buffer->emit('error', [new \RuntimeException('Whoops')]);
}

/**
4 changes: 2 additions & 2 deletions tests/FunctionalInternetTest.php
Original file line number Diff line number Diff line change
@@ -87,8 +87,8 @@ public function testUploadBiggerBlockSecure()

$stream = stream_socket_client('ssl://httpbin.org:443');

// PHP < 7.1.4 (and PHP < 7.0.18) suffers from a bug when writing big
// chunks of data over TLS streams at once.
// PHP < 7.1.4 suffers from a bug when writing big chunks of data over
// TLS streams at once.
// We work around this by limiting the write chunk size to 8192 bytes
// here to also support older PHP versions.
// See https://github.com/reactphp/socket/issues/105
12 changes: 4 additions & 8 deletions tests/ReadableResourceStreamTest.php
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
{
$loop = $this->createLoopMock();

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

@@ -64,13 +64,9 @@ public function testConstructorThrowsExceptionOnInvalidStream()
*/
public function testConstructorThrowsExceptionOnWriteOnlyStream()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not report fopen mode for STDOUT');
}

$loop = $this->createLoopMock();

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

@@ -85,7 +81,7 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
unlink($name);

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

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

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

8 changes: 4 additions & 4 deletions tests/Stub/ReadableStreamStub.php
Original file line number Diff line number Diff line change
@@ -20,19 +20,19 @@ public function isReadable()
// trigger data event
public function write($data)
{
$this->emit('data', array($data));
$this->emit('data', [$data]);
}

// trigger error event
public function error($error)
{
$this->emit('error', array($error));
$this->emit('error', [$error]);
}

// trigger end event
public function end()
{
$this->emit('end', array());
$this->emit('end', []);
}

public function pause()
@@ -52,7 +52,7 @@ public function close()
$this->emit('close');
}

public function pipe(WritableStreamInterface $dest, array $options = array())
public function pipe(WritableStreamInterface $dest, array $options = [])
{
Util::pipe($this, $dest, $options);

59 changes: 5 additions & 54 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -39,62 +39,13 @@ protected function expectCallableNever()

protected function createCallableMock()
{
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
$builder = $this->getMockBuilder(\stdClass::class);
if (method_exists($builder, 'addMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
return $builder->addMethods(['__invoke'])->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 9
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4 - PHPUnit 5.1
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}

public function assertContainsString($needle, $haystack)
{
if (method_exists($this, 'assertStringContainsString')) {
// PHPUnit 7.5+
$this->assertStringContainsString($needle, $haystack);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertContains($needle, $haystack);
}
}

public function assertContainsStringIgnoringCase($needle, $haystack)
{
if (method_exists($this, 'assertStringContainsStringIgnoringCase')) {
// PHPUnit 7.5+
$this->assertStringContainsStringIgnoringCase($needle, $haystack);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertContains($needle, $haystack, '', true);
}
}

public function assertSameIgnoringCase($expected, $actual)
{
if (method_exists($this, 'assertEqualsIgnoringCase')) {
// PHPUnit 7.5+
$this->assertEqualsIgnoringCase($expected, $actual);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertSame($expected, $actual);
// legacy PHPUnit
return $builder->setMethods(['__invoke'])->getMock();
}
}
}
6 changes: 3 additions & 3 deletions tests/ThroughStreamTest.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ class ThroughStreamTest extends TestCase
*/
public function itShouldRejectInvalidCallback()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
new ThroughStream(123);
}

@@ -185,7 +185,7 @@ public function pipingStuffIntoItShouldWork()
$through->on('data', $this->expectCallableOnceWith('foo'));

$readable->pipe($through);
$readable->emit('data', array('foo'));
$readable->emit('data', ['foo']);
}

/** @test */
@@ -243,7 +243,7 @@ public function writeAfterEndShouldReturnFalse()
public function writeDataWillCloseStreamShouldReturnFalse()
{
$through = new ThroughStream();
$through->on('data', array($through, 'close'));
$through->on('data', [$through, 'close']);

$this->assertFalse($through->write('foo'));
}
8 changes: 4 additions & 4 deletions tests/UtilTest.php
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ public function testPipeWithoutEnd()
->expects($this->never())
->method('end');

Util::pipe($readable, $writable, array('end' => false));
Util::pipe($readable, $writable, ['end' => false]);

$readable->end();
}
@@ -253,12 +253,12 @@ public function forwardEventsShouldSetupForwards()
$source = new ThroughStream();
$target = new ThroughStream();

Util::forwardEvents($source, $target, array('data'));
Util::forwardEvents($source, $target, ['data']);
$target->on('data', $this->expectCallableOnce());
$target->on('foo', $this->expectCallableNever());

$source->emit('data', array('hello'));
$source->emit('foo', array('bar'));
$source->emit('data', ['hello']);
$source->emit('foo', ['bar']);
}

private function createLoopMock()
16 changes: 6 additions & 10 deletions tests/WritableResourceStreamTest.php
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ public function testConstructorThrowsIfNotAValidStreamResource()
$stream = null;
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
new WritableResourceStream($stream, $loop);
}

@@ -68,7 +68,7 @@ public function testConstructorThrowsExceptionOnReadOnlyStream()
$stream = fopen('php://temp', 'r');
$loop = $this->createLoopMock();

$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
new WritableResourceStream($stream, $loop);
}

@@ -83,7 +83,7 @@ public function testConstructorThrowsExceptionOnReadOnlyStreamWithExcessiveMode(
unlink($name);

$loop = $this->createLoopMock();
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
new WritableResourceStream($stream, $loop);
}

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

$this->setExpectedException('RuntimeException');
$this->expectException('RuntimeException');
new WritableResourceStream($stream, $loop);
}

@@ -347,10 +347,6 @@ public function testEndWithoutDataDoesNotCloseIfWritableResourceStreamIsFull()
*/
public function testEndWithDataClosesImmediatelyIfWritableResourceStreamFlushes()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on HHVM');
}

$stream = fopen('php://temp', 'r+');
$filterBuffer = '';
$loop = $this->createLoopMock();
@@ -411,7 +407,7 @@ public function testClose()
$buffer->close();
$this->assertFalse($buffer->isWritable());

$this->assertEquals(array(), $buffer->listeners('close'));
$this->assertEquals([], $buffer->listeners('close'));
}

/**
@@ -507,7 +503,7 @@ public function testWritingToClosedStream()
$buffer->handleWrite();

$this->assertInstanceOf('Exception', $error);
$this->assertSameIgnoringCase('Unable to write to stream: fwrite(): send of 3 bytes failed with errno=32 Broken pipe', $error->getMessage());
$this->assertEqualsIgnoringCase('Unable to write to stream: fwrite(): send of 3 bytes failed with errno=32 Broken pipe', $error->getMessage());
}

private function createWriteableLoopMock()

0 comments on commit e4313ea

Please sign in to comment.