Skip to content

Commit

Permalink
Update to new promise-based dns API in react/dns v0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Nov 18, 2012
1 parent 0046366 commit 51e6d44
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 104 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
CHANGELOG
=========

* 0.1.1 (2012-11-18)

* Use promise-based DNS resolver in react/dns v0.2.4

* 0.1.0 (2012-11-08)

* First tagged release
Expand Down
76 changes: 39 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 0 additions & 55 deletions src/React/Whois/BufferedStreamPromise.php

This file was deleted.

13 changes: 5 additions & 8 deletions src/React/Whois/Client.php
Expand Up @@ -6,6 +6,7 @@
use React\Curry\Util as Curry;
use React\Dns\Resolver\Resolver;
use React\Stream\ReadableStreamInterface;
use React\Stream\BufferedSink;

class Client
{
Expand All @@ -27,14 +28,10 @@ public function query($domain)

public function resolveWhoisServer($domain)
{
$deferred = new Deferred();

$tld = substr(strrchr($domain, '.'), 1);
$target = $tld.'.whois-servers.net';

$this->dns->resolve($target, array($deferred, 'resolve'));

return $deferred->promise();
return $this->dns->resolve($target);
}

public function queryWhoisServer($domain, $ip)
Expand All @@ -54,9 +51,9 @@ public function normalizeLinefeeds($data)

public function streamGetContents(ReadableStreamInterface $input)
{
$contents = new BufferedStreamPromise();
$input->pipe($contents);
$sink = new BufferedSink();
$input->pipe($sink);

return $contents;
return $sink->promise();
}
}
8 changes: 4 additions & 4 deletions tests/React/Whois/ClientTest.php
Expand Up @@ -2,6 +2,8 @@

namespace React\Whois;

use React\Promise\FulfilledPromise;

class ClientTest extends TestCase
{
/** @test */
Expand All @@ -15,17 +17,15 @@ public function clientShouldGetCorrectWhoisServerAndQueryIt()
->method('__invoke')
->with($result);

// whois.nic.io => 193.223.78.152
$resolver = $this->getMockBuilder('React\Dns\Resolver\Resolver')
->disableOriginalConstructor()
->getMock();
$resolver
->expects($this->once())
->method('resolve')
->with('io.whois-servers.net')
->will($this->returnCallback(function ($domain, $callback) {
// whois.nic.io
call_user_func($callback, '193.223.78.152');
}));
->will($this->returnValue(new FulfilledPromise('193.223.78.152')));

$conn = $this->getMockBuilder('React\Whois\Stub\ConnectionStub')
->setMethods(array(
Expand Down

0 comments on commit 51e6d44

Please sign in to comment.