Skip to content

Commit 6170cff

Browse files
committed
Add functional test
1 parent e1eaadb commit 6170cff

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

tests/FunctionalResolverTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace React\Tests\Dns;
4+
5+
use React\EventLoop\Factory as LoopFactory;
6+
use React\Dns\Resolver\Resolver;
7+
use React\Dns\Resolver\Factory;
8+
9+
class FunctionalTest extends \PHPUnit_Framework_TestCase
10+
{
11+
public function setUp()
12+
{
13+
$this->loop = LoopFactory::create();
14+
15+
$factory = new Factory();
16+
$this->resolver = $factory->create('8.8.8.8', $this->loop);
17+
}
18+
19+
public function testResolveGoogleResolves()
20+
{
21+
$promise = $this->resolver->resolve('google.com');
22+
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
23+
24+
$this->loop->run();
25+
}
26+
27+
public function testResolveInvalidRejects()
28+
{
29+
$promise = $this->resolver->resolve('example.invalid');
30+
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
31+
32+
$this->loop->run();
33+
}
34+
35+
protected function expectCallableOnce()
36+
{
37+
$mock = $this->createCallableMock();
38+
$mock
39+
->expects($this->once())
40+
->method('__invoke');
41+
42+
return $mock;
43+
}
44+
45+
protected function expectCallableNever()
46+
{
47+
$mock = $this->createCallableMock();
48+
$mock
49+
->expects($this->never())
50+
->method('__invoke');
51+
52+
return $mock;
53+
}
54+
55+
protected function createCallableMock()
56+
{
57+
return $this->getMock('React\Tests\Dns\CallableStub');
58+
}
59+
}

0 commit comments

Comments
 (0)