Skip to content

Commit

Permalink
Forward compatibility with react/promise 3
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Dec 3, 2019

Verified

This commit was signed with the committer’s verified signature.
taddes Taddes
1 parent d3e7198 commit 2a0f25f
Showing 3 changed files with 26 additions and 20 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -8,14 +8,20 @@
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/dns": "^1.1",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
"react/promise": "^2.6.0 || ^1.2.1",
"react/promise-timer": "^1.4.0",
"react/promise": "dev-master as 2.999.9999",
"react/promise-timer": "dev-promise-3 as 1.6.0",
"react/stream": "^1.1"
},
"require-dev": {
"clue/block-react": "^1.2",
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/WyriHaximus-labs/promise-timer"
}
],
"autoload": {
"psr-4": {
"React\\Socket\\": "src"
12 changes: 6 additions & 6 deletions tests/DnsConnectorTest.php
Original file line number Diff line number Diff line change
@@ -23,47 +23,47 @@ public function setUp()
public function testPassByResolverIfGivenIp()
{
$this->resolver->expects($this->never())->method('resolve');
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('127.0.0.1:80'))->will($this->returnValue(Promise\reject()));
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('127.0.0.1:80'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));

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

public function testPassThroughResolverIfGivenHost()
{
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
$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'))));

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

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

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

public function testPassByResolverIfGivenCompleteUri()
{
$this->resolver->expects($this->never())->method('resolve');
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject()));
$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'))));

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

public function testPassThroughResolverIfGivenCompleteUri()
{
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
$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()));
$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'))));

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

public function testPassThroughResolverIfGivenExplicitHost()
{
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4')));
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject()));
$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'))));

$this->connector->connect('scheme://google.com:80/?hostname=google.de');
}
24 changes: 12 additions & 12 deletions tests/HappyEyeBallsConnectorTest.php
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public function testPassByResolverIfGivenIp()
public function testPassByResolverIfGivenIpv6()
{
$this->resolver->expects($this->never())->method('resolveAll');
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80'))->will($this->returnValue(Promise\reject()));
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80'))->will($this->returnValue(Promise\reject(new \Exception('reject'))));

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

@@ -91,7 +91,7 @@ public function testPassByResolverIfGivenIpv6()
public function testPassThroughResolverIfGivenHost()
{
$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'))));
$this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject()));
$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'))));

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

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

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

@@ -111,7 +111,7 @@ public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6()
public function testPassByResolverIfGivenCompleteUri()
{
$this->resolver->expects($this->never())->method('resolveAll');
$this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject()));
$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'))));

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

@@ -121,7 +121,7 @@ public function testPassByResolverIfGivenCompleteUri()
public function testPassThroughResolverIfGivenCompleteUri()
{
$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'))));
$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()));
$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'))));

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

@@ -131,7 +131,7 @@ public function testPassThroughResolverIfGivenCompleteUri()
public function testPassThroughResolverIfGivenExplicitHost()
{
$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'))));
$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()));
$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'))));

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

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

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

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

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

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

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

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

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

$this->loop->run();
@@ -290,10 +290,10 @@ public function testAttemptsToConnectBothIpv6AndIpv4AddressesAlternatingIpv6AndI
$i = 0;
while (count($ipv6) > 0 || count($ipv4) > 0) {
if (count($ipv6) > 0) {
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://[' . array_shift($ipv6) . ']:80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
$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'))));
}
if (count($ipv4) > 0) {
$this->tcp->expects($this->at($i++))->method('connect')->with($this->equalTo('scheme://' . array_shift($ipv4) . ':80/?hostname=google.com'))->will($this->returnValue(Promise\reject()));
$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'))));
}
}

0 comments on commit 2a0f25f

Please sign in to comment.