Skip to content

Commit fe0b72e

Browse files
committed
Update test suite and remove legacy PHPUnit workarounds
1 parent c8c9d42 commit fe0b72e

24 files changed

+511
-548
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"react/stream": "^1.2"
3535
},
3636
"require-dev": {
37-
"phpunit/phpunit": "^9.6 || ^5.7",
37+
"phpunit/phpunit": "^9.6 || ^7.5",
3838
"react/async": "^4 || ^3",
3939
"react/promise-stream": "^1.4",
4040
"react/promise-timer": "^1.10"

phpunit.xml.legacy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

tests/ConnectionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace React\Tests\Socket;
44

5+
use React\EventLoop\LoopInterface;
56
use React\Socket\Connection;
67

78
class ConnectionTest extends TestCase
89
{
910
public function testCloseConnectionWillCloseSocketResource()
1011
{
1112
$resource = fopen('php://memory', 'r+');
12-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
13+
$loop = $this->createMock(LoopInterface::class);
1314

1415
$connection = new Connection($resource, $loop);
1516
$connection->close();
@@ -20,7 +21,7 @@ public function testCloseConnectionWillCloseSocketResource()
2021
public function testCloseConnectionWillRemoveResourceFromLoopBeforeClosingResource()
2122
{
2223
$resource = fopen('php://memory', 'r+');
23-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
24+
$loop = $this->createMock(LoopInterface::class);
2425
$loop->expects($this->once())->method('addWriteStream')->with($resource);
2526

2627
$onRemove = null;

tests/ConnectorTest.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace React\Tests\Socket;
44

5-
use React\Socket\Connector;
5+
use React\Dns\Resolver\ResolverInterface;
6+
use React\EventLoop\LoopInterface;
67
use React\Promise\Promise;
8+
use React\Socket\Connector;
9+
use React\Socket\ConnectorInterface;
710

811
class ConnectorTest extends TestCase
912
{
@@ -19,12 +22,12 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
1922
$ref->setAccessible(true);
2023
$loop = $ref->getValue($connectors['tcp']);
2124

22-
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
25+
$this->assertInstanceOf(LoopInterface::class, $loop);
2326
}
2427

2528
public function testConstructWithLoopAssignsGivenLoop()
2629
{
27-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
30+
$loop = $this->createMock(LoopInterface::class);
2831

2932
$connector = new Connector([], $loop);
3033

@@ -36,12 +39,12 @@ public function testConstructWithLoopAssignsGivenLoop()
3639
$ref->setAccessible(true);
3740
$loop = $ref->getValue($connectors['tcp']);
3841

39-
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
42+
$this->assertInstanceOf(LoopInterface::class, $loop);
4043
}
4144

4245
public function testConstructWithContextAssignsGivenContext()
4346
{
44-
$tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
47+
$tcp = $this->createMock(ConnectorInterface::class);
4548

4649
$connector = new Connector([
4750
'tcp' => $tcp,
@@ -58,10 +61,10 @@ public function testConstructWithContextAssignsGivenContext()
5861

5962
public function testConnectorUsesTcpAsDefaultScheme()
6063
{
61-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
64+
$loop = $this->createMock(LoopInterface::class);
6265

6366
$promise = new Promise(function () { });
64-
$tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
67+
$tcp = $this->createMock(ConnectorInterface::class);
6568
$tcp->expects($this->once())->method('connect')->with('127.0.0.1:80')->willReturn($promise);
6669

6770
$connector = new Connector([
@@ -73,10 +76,10 @@ public function testConnectorUsesTcpAsDefaultScheme()
7376

7477
public function testConnectorPassedThroughHostnameIfDnsIsDisabled()
7578
{
76-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
79+
$loop = $this->createMock(LoopInterface::class);
7780

7881
$promise = new Promise(function () { });
79-
$tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
82+
$tcp = $this->createMock(ConnectorInterface::class);
8083
$tcp->expects($this->once())->method('connect')->with('tcp://google.com:80')->willReturn($promise);
8184

8285
$connector = new Connector([
@@ -89,88 +92,88 @@ public function testConnectorPassedThroughHostnameIfDnsIsDisabled()
8992

9093
public function testConnectorWithUnknownSchemeAlwaysFails()
9194
{
92-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
95+
$loop = $this->createMock(LoopInterface::class);
9396
$connector = new Connector([], $loop);
9497

9598
$promise = $connector->connect('unknown://google.com:80');
9699

97100
$promise->then(null, $this->expectCallableOnceWithException(
98-
'RuntimeException',
101+
\RuntimeException::class,
99102
'No connector available for URI scheme "unknown" (EINVAL)',
100103
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : (defined('PCNTL_EINVAL') ? PCNTL_EINVAL : 22)
101104
));
102105
}
103106

104107
public function testConnectorWithDisabledTcpDefaultSchemeAlwaysFails()
105108
{
106-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
109+
$loop = $this->createMock(LoopInterface::class);
107110
$connector = new Connector([
108111
'tcp' => false
109112
], $loop);
110113

111114
$promise = $connector->connect('google.com:80');
112115

113116
$promise->then(null, $this->expectCallableOnceWithException(
114-
'RuntimeException',
117+
\RuntimeException::class,
115118
'No connector available for URI scheme "tcp" (EINVAL)',
116119
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : (defined('PCNTL_EINVAL') ? PCNTL_EINVAL : 22)
117120
));
118121
}
119122

120123
public function testConnectorWithDisabledTcpSchemeAlwaysFails()
121124
{
122-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
125+
$loop = $this->createMock(LoopInterface::class);
123126
$connector = new Connector([
124127
'tcp' => false
125128
], $loop);
126129

127130
$promise = $connector->connect('tcp://google.com:80');
128131

129132
$promise->then(null, $this->expectCallableOnceWithException(
130-
'RuntimeException',
133+
\RuntimeException::class,
131134
'No connector available for URI scheme "tcp" (EINVAL)',
132135
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : (defined('PCNTL_EINVAL') ? PCNTL_EINVAL : 22)
133136
));
134137
}
135138

136139
public function testConnectorWithDisabledTlsSchemeAlwaysFails()
137140
{
138-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
141+
$loop = $this->createMock(LoopInterface::class);
139142
$connector = new Connector([
140143
'tls' => false
141144
], $loop);
142145

143146
$promise = $connector->connect('tls://google.com:443');
144147

145148
$promise->then(null, $this->expectCallableOnceWithException(
146-
'RuntimeException',
149+
\RuntimeException::class,
147150
'No connector available for URI scheme "tls" (EINVAL)',
148151
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : (defined('PCNTL_EINVAL') ? PCNTL_EINVAL : 22)
149152
));
150153
}
151154

152155
public function testConnectorWithDisabledUnixSchemeAlwaysFails()
153156
{
154-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
157+
$loop = $this->createMock(LoopInterface::class);
155158
$connector = new Connector([
156159
'unix' => false
157160
], $loop);
158161

159162
$promise = $connector->connect('unix://demo.sock');
160163

161164
$promise->then(null, $this->expectCallableOnceWithException(
162-
'RuntimeException',
165+
\RuntimeException::class,
163166
'No connector available for URI scheme "unix" (EINVAL)',
164167
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : (defined('PCNTL_EINVAL') ? PCNTL_EINVAL : 22)
165168
));
166169
}
167170

168171
public function testConnectorUsesGivenResolverInstance()
169172
{
170-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
173+
$loop = $this->createMock(LoopInterface::class);
171174

172175
$promise = new Promise(function () { });
173-
$resolver = $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock();
176+
$resolver = $this->createMock(ResolverInterface::class);
174177
$resolver->expects($this->once())->method('resolve')->with('google.com')->willReturn($promise);
175178

176179
$connector = new Connector([
@@ -183,14 +186,14 @@ public function testConnectorUsesGivenResolverInstance()
183186

184187
public function testConnectorUsesResolvedHostnameIfDnsIsUsed()
185188
{
186-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
189+
$loop = $this->createMock(LoopInterface::class);
187190

188191
$promise = new Promise(function ($resolve) { $resolve('127.0.0.1'); });
189-
$resolver = $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock();
192+
$resolver = $this->createMock(ResolverInterface::class);
190193
$resolver->expects($this->once())->method('resolve')->with('google.com')->willReturn($promise);
191194

192195
$promise = new Promise(function () { });
193-
$tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
196+
$tcp = $this->createMock(ConnectorInterface::class);
194197
$tcp->expects($this->once())->method('connect')->with('tcp://127.0.0.1:80?hostname=google.com')->willReturn($promise);
195198

196199
$connector = new Connector([

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy