8000 Update test suite and remove legacy PHPUnit workarounds · reactphp/stream@f699f29 · GitHub
[go: up one dir, main page]

Skip to content

Commit f699f29

Browse files
committed
Update test suite and remove legacy PHPUnit workarounds
1 parent 461c216 commit f699f29

7 files changed

+57
-122
lines changed

tests/DuplexResourceStreamIntegrationTest.php

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,47 @@
66
use React\Stream\DuplexResourceStream;
77
use React\Stream\ReadableResourceStream;
88
use React\EventLoop\ExtEventLoop;
9-
use React\EventLoop\ExtLibeventLoop;
10-
use React\EventLoop\ExtLibevLoop;
9+
use React\EventLoop\ExtEvLoop;
10+
use React\EventLoop\ExtUvLoop;
1111
use React\EventLoop\LoopInterface;
12-
use React\EventLoop\LibEventLoop;
13-
use React\EventLoop\LibEvLoop;
1412
use React\EventLoop\StreamSelectLoop;
1513

1614
class DuplexResourceStreamIntegrationTest extends TestCase
1715
{
1816
public function loopProvider()
1917
{
20-
return array(
21-
array(
22-
function() {
23-
return true;
24-
},
25-
function () {
26-
return new StreamSelectLoop();
27-
}
28-
),
29-
array(
30-
function () {
31-
return function_exists('event_base_new');
32-
},
33-
function () {
34-
return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : new LibEventLoop();
35-
}
36-
),
37-
array(
38-
function () {
39-
return class_exists('libev\EventLoop');
40-
},
41-
function () {
42-
return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
43-
}
44-
),
45-
array(
46-
function () {
47-
return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop');
48-
},
49-
function () {
50-
return new ExtEventLoop();
51-
}
52-
)
53-
);
18+
yield [
19+
function() {
20+
return true;
21+
},
22+
function () {
23+
return new StreamSelectLoop();
24+
}
25+
];
26+
yield [
27+
function () {
28+
return class_exists('EvLoop');
29+
},
30+
function () {
31+
return new ExtEvLoop();
32+
}
33+
];
34+
yield [
35+
function () {
36+
return \function_exists('uv_loop_new');
37+
},
38+
function () {
39+
return new ExtUvLoop();
40+
}
41+
];
42+
yield [
43+
function () {
44+
return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop');
45+
},
46+
function () {
47+
return new ExtEventLoop();
48+
}
49+
];
5450
}
5551

5652
/**

tests/DuplexResourceStreamTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
5656
{
5757
$loop = $this->createLoopMock();
5858

59-
$this->setExpectedException('InvalidArgumentException');
59+
$this->expectException('InvalidArgumentException');
6060
new DuplexResourceStream('breakme', $loop);
6161
}
6262

@@ -65,13 +65,9 @@ public function testConstructorThrowsExceptionOnInvalidStream()
6565
*/
6666
public function testConstructorThrowsExceptionOnWriteOnlyStream()
6767
{
68-
if (defined('HHVM_VERSION')) {
69-
$this->markTestSkipped('HHVM does not report fopen mode for STDOUT');
70-
}
71-
7268
$loop = $this->createLoopMock();
7369

74-
$this->setExpectedException('InvalidArgumentException');
70+
$this->expectException('InvalidArgumentException');
7571
new DuplexResourceStream(STDOUT, $loop);
7672
}
7773

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

8884
$loop = $this->createLoopMock();
89-
$this->setExpectedException('InvalidArgumentException');
85+
$this->expectException('InvalidArgumentException');
9086
new DuplexResourceStream($stream, $loop);
9187
}
9288

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

105-
$this->setExpectedException('RunTimeException');
101+
$this->expectException('RunTimeException');
106102
new DuplexResourceStream($stream, $loop);
107103
}
108104

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

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

137-
$this->setExpectedException('RunTimeException');
133+
$this->expectException('RunTimeException');
138134
new DuplexResourceStream($stream, $loop, null, $buffer);
139135
}
140136

tests/FunctionalInternetTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public function testUploadBiggerBlockSecure()
8787

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

90-
// PHP < 7.1.4 (and PHP < 7.0.18) suffers from a bug when writing big
91-
// chunks of data over TLS streams at once.
90+
// PHP < 7.1.4 suffers from a bug when writing big chunks of data over
91+
// TLS streams at once.
9292
// We work around this by limiting the write chunk size to 8192 bytes
9393
// here to also support older PHP versions.
9494
// See https://github.com/reactphp/socket/issues/105

tests/ReadableResourceStreamTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testConstructorThrowsExceptionOnInvalidStream()
5555
{
5656
$loop = $this->createLoopMock();
5757

58-
$this->setExpectedException('InvalidArgumentException');
58+
$this->expectException('InvalidArgumentException');
5959
new ReadableResourceStream(false, $loop);
6060
}
6161

@@ -64,13 +64,9 @@ public function testConstructorThrowsExceptionOnInvalidStream()
6464
*/
6565
public function testConstructorThrowsExceptionOnWriteOnlyStream()
6666
{
67-
if (defined('HHVM_VERSION')) {
68-
$this->markTestSkipped('HHVM does not report fopen mode for STDOUT');
69-
}
70-
7167
$loop = $this->createLoopMock();
7268

73-
$this->setExpectedException('InvalidArgumentException');
69+
$this->expectException('InvalidArgumentException');
7470
new ReadableResourceStream(STDOUT, $loop);
7571
}
7672

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

8783
$loop = $this->createLoopMock();
88-
$this->setExpectedException('InvalidArgumentException');
84+
$this->expectException('InvalidArgumentException');
8985
new ReadableResourceStream($stream, $loop);
9086
}
9187

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

104-
$this->setExpectedException('RuntimeException');
100+
$this->expectException('RuntimeException');
105101
new ReadableResourceStream($stream, $loop);
106102
}
107103

tests/TestCase.php

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,13 @@ protected function expectCallableNever()
3939

4040
protected function createCallableMock()
4141
{
42-
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
42+
$builder = $this->getMockBuilder(\stdClass::class);
43+
if (method_exists($builder, 'addMethods')) {
4344
// PHPUnit 9+
44-
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
45+
return $builder->addMethods(['__invoke'])->getMock();
4546
} else {
46-
// legacy PHPUnit 4 - PHPUnit 9
47-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
48-
}
49-
}
50-
51-
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
52-
{
53-
if (method_exists($this, 'expectException')) {
54-
// PHPUnit 5.2+
55-
$this->expectException($exception);
56-
if ($exceptionMessage !== '') {
57-
$this->expectExceptionMessage($exceptionMessage);
58-
}
59-
if ($exceptionCode !== null) {
60-
$this->expectExceptionCode($exceptionCode);
61-
}
62-
} else {
63-
// legacy PHPUnit 4 - PHPUnit 5.1
64-
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
65-
}
66-
}
67-
68-
public function assertContainsString($needle, $haystack)
69-
{
70-
if (method_exists($this, 'assertStringContainsString')) {
71-
// PHPUnit 7.5+
72-
$this->assertStringContainsString($needle, $haystack);
73-
} else {
74-
// legacy PHPUnit 4 - PHPUnit 7.5
75-
$this->assertContains($needle, $haystack);
76-
}
77-
}
78-
79-
public function assertContainsStringIgnoringCase($needle, $haystack)
80-
{
81-
if (method_exists($this, 'assertStringContainsStringIgnoringCase')) {
82-
// PHPUnit 7.5+
83-
$this->assertStringContainsStringIgnoringCase($needle, $haystack);
84-
} else {
85-
// legacy PHPUnit 4 - PHPUnit 7.5
86-
$this->assertContains($needle, $haystack, '', true);
87-
}
88-
}
89-
90-
public function assertSameIgnoringCase($expected, $actual)
91-
{
92-
if (method_exists($this, 'assertEqualsIgnoringCase')) {
93-
// PHPUnit 7.5+
94-
$this->assertEqualsIgnoringCase($expected, $actual);
95-
} else {
96-
// legacy PHPUnit 4 - PHPUnit 7.5
97-
$this->assertSame($expected, $actual);
47+
// legacy PHPUnit
48+
return $builder->setMethods(['__invoke'])->getMock();
9849
}
9950
}
10051
}

tests/ThroughStreamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ThroughStreamTest extends TestCase
1414
*/
1515
public function itShouldRejectInvalidCallback()
1616
{
17-
$this->setExpectedException('InvalidArgumentException');
17+
$this->expectException('InvalidArgumentException');
1818
new ThroughStream(123);
1919
}
2020

tests/WritableResourceStreamTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testConstructorThrowsIfNotAValidStreamResource()
5656
$stream = null;
5757
$loop = $this->createLoopMock();
5858

59-
$this->setExpectedException('InvalidArgumentException');
59+
$this->expectException('InvalidArgumentException');
6060
new WritableResourceStream($stream, $loop);
6161
}
6262

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

71-
$this->setExpectedException('InvalidArgumentException');
71+
$this->expectException('InvalidArgumentException');
7272
new WritableResourceStream($stream, $loop);
7373
}
7474

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

8585
$loop = $this->createLoopMock();
86-
$this->setExpectedException('InvalidArgumentException');
86+
$this->expectException('InvalidArgumentException');
8787
new WritableResourceStream($stream, $loop);
8888
}
8989

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

102-
$this->setExpectedException('RuntimeException');
102+
$this->expectException('RuntimeException');
103103
new WritableResourceStream($stream, $loop);
104104
}
105105

@@ -347,10 +347,6 @@ public function testEndWithoutDataDoesNotCloseIfWritableResourceStreamIsFull()
347347
*/
348348
public function testEndWithDataClosesImmediatelyIfWritableResourceStreamFlushes()
349349
{
350-
if (defined('HHVM_VERSION')) {
351-
$this->markTestSkipped('Not supported on HHVM');
352-
}
353-
354350
$stream = fopen('php://temp', 'r+');
355351
$filterBuffer = '';
356352
$loop = $this->createLoopMock();
@@ -411,7 +407,7 @@ public function testClose()
411407
$buffer->close();
412408
$this->assertFalse($buffer->isWritable());
413409

414-
$this->assertEquals(array(), $buffer->listeners('close'));
410+
$this->assertEquals([], $buffer->listeners('close'));
415411
}
416412

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

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

513509
private function createWriteableLoopMock()

0 commit comments

Comments
 (0)
0