diff --git a/composer.json b/composer.json index 6a062273..9afaad51 100644 --- a/composer.json +++ b/composer.json @@ -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.999", + "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" diff --git a/tests/DnsConnectorTest.php b/tests/DnsConnectorTest.php index d3399ea8..982e1a29 100644 --- a/tests/DnsConnectorTest.php +++ b/tests/DnsConnectorTest.php @@ -23,7 +23,7 @@ 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'); } @@ -31,7 +31,7 @@ public function testPassByResolverIfGivenIp() 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'); } @@ -39,7 +39,7 @@ public function testPassThroughResolverIfGivenHost() 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'); } @@ -47,7 +47,7 @@ public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6() 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'); } @@ -55,7 +55,7 @@ public function testPassByResolverIfGivenCompleteUri() 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'); } @@ -63,7 +63,7 @@ public function testPassThroughResolverIfGivenCompleteUri() 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'); } diff --git a/tests/HappyEyeBallsConnectorTest.php b/tests/HappyEyeBallsConnectorTest.php index cb7a0aa2..317c0daf 100644 --- a/tests/HappyEyeBallsConnectorTest.php +++ b/tests/HappyEyeBallsConnectorTest.php @@ -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')))); } }