Skip to content

Commit 2a0f25f

Browse files
committed
Forward compatibility with react/promise 3
1 parent d3e7198 commit 2a0f25f

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
99
"react/dns": "^1.1",
1010
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
11-
"react/promise": "^2.6.0 || ^1.2.1",
12-
"react/promise-timer": "^1.4.0",
11+
"react/promise": "dev-master as 2.999.9999",
12+
"react/promise-timer": "dev-promise-3 as 1.6.0",
1313
"react/stream": "^1.1"
1414
},
1515
"require-dev": {
1616
"clue/block-react": "^1.2",
1717
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
1818
},
19+
"repositories": [
20+
{
21+
"type": "vcs",
22+
"url": "https://github.com/WyriHaximus-labs/promise-timer"
23+
}
24+
],
1925
"autoload": {
2026
"psr-4": {
2127
"React\\Socket\\": "src"

tests/DnsConnectorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,47 @@ public function setUp()
2323
public function testPassByResolverIfGivenIp()
2424
{
2525
$this->resolver->expects($this->never())->method('resolve');
26-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('127.0.0.1:80'))->will($this->returnValue(Promise\reject()));
26+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('127.0.0.1:80'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
2727

2828
$this->connector->connect('127.0.0.1:80');
2929
}
3030

3131
public function testPassThroughResolverIfGivenHost()
3232
{
3333
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
34-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
34+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
3535

3636
$this->connector->connect('google.com:80');
3737
}
3838

3939
public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6()
4040
{
4141
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('::1')));
42-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
42+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
4343

4444
$this->connector->connect('google.com:80');
4545
}
4646

4747
public function testPassByResolverIfGivenCompleteUri()
4848
{
4949
$this->resolver->expects($this->never())->method('resolve');
50-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject()));
50+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
5151

5252
$this->connector->connect('scheme://127.0.0.1:80/path?query#fragment');
5353
}
5454

5555
public function testPassThroughResolverIfGivenCompleteUri()
5656
{
5757
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
58-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject()));
58+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
5959

6060
$this->connector->connect('scheme://google.com:80/path?query#fragment');
6161
}
6262

6363
public function testPassThroughResolverIfGivenExplicitHost()
6464
{
6565
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
66-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject()));
66+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
6767

6868
$this->connector->connect('scheme://google.com:80/?hostname=google.de');
6969
}

tests/HappyEyeBallsConnectorTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testPassByResolverIfGivenIp()
8181
public function testPassByResolverIfGivenIpv6()
8282
{
8383
$this->resolver->expects($this->never())->method('resolveAll');
84-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80'))->will($this->returnValue(Promise\reject()));
84+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
8585

8686
$this->connector->connect('[::1]:80');
8787

@@ -91,7 +91,7 @@ public function testPassByResolverIfGivenIpv6()
9191
public function testPassThroughResolverIfGivenHost()
9292
{
9393
$this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
94-
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
94+
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
9595

9696
$this->connector->connect('google.com:80');
9797

@@ -101,7 +101,7 @@ public function testPassThroughResolverIfGivenHost()
101101
public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6()
102102
{
103103
$this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('::1'))));
104-
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
104+
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
105105

106106
$this->connector->connect('google.com:80');
107107

@@ -111,7 +111,7 @@ public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6()
111111
public function testPassByResolverIfGivenCompleteUri()
112112
{
113113
$this->resolver->expects($this->never())->method('resolveAll');
114-
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject()));
114+
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
115115

116116
$this->connector->connect('scheme://127.0.0.1:80/path?query#fragment');
117117

@@ -121,7 +121,7 @@ public function testPassByResolverIfGivenCompleteUri()
121121
public function testPassThroughResolverIfGivenCompleteUri()
122122
{
123123
$this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
124-
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject()));
124+
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
125125

126126
$this->connector->connect('scheme://google.com:80/path?query#fragment');
127127

@@ -131,7 +131,7 @@ public function testPassThroughResolverIfGivenCompleteUri()
131131
public function testPassThroughResolverIfGivenExplicitHost()
132132
{
133133
$this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
134-
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject()));
134+
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
135135

136136
$this->connector->connect('scheme://google.com:80/?hostname=google.de');
137137

@@ -171,12 +171,12 @@ public function testIpv6ResolvesFirstSoIsTheFirstToConnect(array $ipv6, array $i
171171

172172
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve($ipv6)));
173173
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue($deferred->promise()));
174-
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(']:80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
174+
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(']:80/?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
175175

176176
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
177177

178178
$this->loop->addTimer(0.07, function () use ($deferred) {
179-
$deferred->reject();
179+
$deferred->reject(new \Exception('reject'));
180180
});
181181

182182
$this->loop->run();
@@ -191,12 +191,12 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
191191

192192
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue($deferred->promise()));
193193
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve($ipv4)));
194-
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(':80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
194+
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(':80/?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
195195

196196
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
197197

198198
$this->loop->addTimer(0.07, function () use ($deferred) {
199-
$deferred->reject();
199+
$deferred->reject(new \Exception('reject'));
200200
});
201201

202202
$this->loop->run();
@@ -290,10 +290,10 @@ public function testAttemptsToConnectBothIpv6AndIpv4AddressesAlternatingIpv6AndI
290290
$i = 0;
291291
while (count($ipv6) > 0 || count($ipv4) > 0) {
292292
if (count($ipv6) > 0) {
293-
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://[' . array_shift($ipv6) . ']:80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
293+
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://[' . array_shift($ipv6) . ']:80/?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
294294
}
295295
if (count($ipv4) > 0) {
296-
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://' . array_shift($ipv4) . ':80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
296+
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://' . array_shift($ipv4) . ':80/?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));
297297
}
298298
}
299299

0 commit comments

Comments
 (0)