diff --git a/tests/DuplexResourceStreamIntegrationTest.php b/tests/DuplexResourceStreamIntegrationTest.php index 7135e15..6e05ee3 100644 --- a/tests/DuplexResourceStreamIntegrationTest.php +++ b/tests/DuplexResourceStreamIntegrationTest.php @@ -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(); + } + ]; } /** diff --git a/tests/DuplexResourceStreamTest.php b/tests/DuplexResourceStreamTest.php index 7d4d509..eb134de 100644 --- a/tests/DuplexResourceStreamTest.php +++ b/tests/DuplexResourceStreamTest.php @@ -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); } diff --git a/tests/FunctionalInternetTest.php b/tests/FunctionalInternetTest.php index 4f07537..fd062fe 100644 --- a/tests/FunctionalInternetTest.php +++ b/tests/FunctionalInternetTest.php @@ -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 diff --git a/tests/ReadableResourceStreamTest.php b/tests/ReadableResourceStreamTest.php index f534488..58e33e6 100644 --- a/tests/ReadableResourceStreamTest.php +++ b/tests/ReadableResourceStreamTest.php @@ -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); } diff --git a/tests/TestCase.php b/tests/TestCase.php index af07e3e..b161c46 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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(); } } } diff --git a/tests/ThroughStreamTest.php b/tests/ThroughStreamTest.php index 3093136..7983a76 100644 --- a/tests/ThroughStreamTest.php +++ b/tests/ThroughStreamTest.php @@ -14,7 +14,7 @@ class ThroughStreamTest extends TestCase */ public function itShouldRejectInvalidCallback() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException('InvalidArgumentException'); new ThroughStream(123); } diff --git a/tests/WritableResourceStreamTest.php b/tests/WritableResourceStreamTest.php index 678db98..89f4fc5 100644 --- a/tests/WritableResourceStreamTest.php +++ b/tests/WritableResourceStreamTest.php @@ -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()