Skip to content

Commit 9ccda33

Browse files
authored
Merge pull request #204 from clue-labs/loop-tests
Update test suite to use default loop
2 parents 6e16361 + 95fcdf2 commit 9ccda33

File tree

4 files changed

+125
-117
lines changed

4 files changed

+125
-117
lines changed

tests/FunctionalResolverTest.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,37 @@
22

33
namespace React\Tests\Dns;
44

5-
use React\EventLoop\Factory as LoopFactory;
65
use React\Dns\Resolver\Factory;
7-
use React\Dns\RecordNotFoundException;
86
use React\Dns\Model\Message;
7+
use React\EventLoop\Loop;
98

109
class FunctionalResolverTest extends TestCase
1110
{
12-
private $loop;
1311
private $resolver;
1412

1513
/**
1614
* @before
1715
*/
1816
public function setUpResolver()
1917
{
20-
$this->loop = LoopFactory::create();
21-
2218
$factory = new Factory();
23-
$this->resolver = $factory->create('8.8.8.8', $this->loop);
19+
$this->resolver = $factory->create('8.8.8.8');
2420
}
2521

2622
public function testResolveLocalhostResolves()
2723
{
2824
$promise = $this->resolver->resolve('localhost');
2925
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
3026

31-
$this->loop->run();
27+
Loop::run();
3228
}
3329

3430
public function testResolveAllLocalhostResolvesWithArray()
3531
{
3632
$promise = $this->resolver->resolveAll('localhost', Message::TYPE_A);
3733
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());
3834

39-
$this->loop->run();
35+
Loop::run();
4036
}
4137

4238
/**
@@ -47,35 +43,35 @@ public function testResolveGoogleResolves()
4743
$promise = $this->resolver->resolve('google.com');
4844
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
4945

50-
$this->loop->run();
46+
Loop::run();
5147
}
5248

5349
/**
5450
* @group internet
5551
*/
5652
public function testResolveGoogleOverUdpResolves()
5753
{
58-
$factory = new Factory($this->loop);
59-
$this->resolver = $factory->create('udp://8.8.8.8', $this->loop);
54+
$factory = new Factory();
55+
$this->resolver = $factory->create('udp://8.8.8.8');
6056

6157
$promise = $this->resolver->resolve('google.com');
6258
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
6359

64-
$this->loop->run();
60+
Loop::run();
6561
}
6662

6763
/**
6864
* @group internet
6965
*/
7066
public function testResolveGoogleOverTcpResolves()
7167
{
72-
$factory = new Factory($this->loop);
73-
$this->resolver = $factory->create('tcp://8.8.8.8', $this->loop);
68+
$factory = new Factory();
69+
$this->resolver = $factory->create('tcp://8.8.8.8');
7470

7571
$promise = $this->resolver->resolve('google.com');
7672
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
7773

78-
$this->loop->run();
74+
Loop::run();
7975
}
8076

8177
/**
@@ -84,25 +80,25 @@ public function testResolveGoogleOverTcpResolves()
8480
public function testResolveAllGoogleMxResolvesWithCache()
8581
{
8682
$factory = new Factory();
87-
$this->resolver = $factory->createCached('8.8.8.8', $this->loop);
83+
$this->resolver = $factory->createCached('8.8.8.8');
8884

8985
$promise = $this->resolver->resolveAll('google.com', Message::TYPE_MX);
9086
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());
9187

92-
$this->loop->run();
88+
Loop::run();
9389
}
9490
/**
9591
* @group internet
9692
*/
9793
public function testResolveAllGoogleCaaResolvesWithCache()
9894
{
9995
$factory = new Factory();
100-
$this->resolver = $factory->createCached('8.8.8.8', $this->loop);
96+
$this->resolver = $factory->createCached('8.8.8.8');
10197

10298
$promise = $this->resolver->resolveAll('google.com', Message::TYPE_CAA);
10399
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());
104100

105-
$this->loop->run();
101+
Loop::run();
106102
}
107103

108104
/**
@@ -112,7 +108,7 @@ public function testResolveInvalidRejects()
112108
{
113109
$promise = $this->resolver->resolve('example.invalid');
114110

115-
$this->loop->run();
111+
Loop::run();
116112

117113
$exception = null;
118114
$promise->then(null, function ($reason) use (&$exception) {
@@ -134,7 +130,7 @@ public function testResolveCancelledRejectsImmediately()
134130
$promise->cancel();
135131

136132
$time = microtime(true);
137-
$this->loop->run();
133+
Loop::run();
138134
$time = microtime(true) - $time;
139135

140136
$this->assertLessThan(0.1, $time);
@@ -156,7 +152,7 @@ public function testResolveAllInvalidTypeRejects()
156152
{
157153
$promise = $this->resolver->resolveAll('google.com', Message::TYPE_PTR);
158154

159-
$this->loop->run();
155+
Loop::run();
160156

161157
$exception = null;
162158
$promise->then(null, function ($reason) use (&$exception) {
@@ -172,7 +168,7 @@ public function testResolveAllInvalidTypeRejects()
172168
public function testInvalidResolverDoesNotResolveGoogle()
173169
{
174170
$factory = new Factory();
175-
$this->resolver = $factory->create('255.255.255.255', $this->loop);
171+
$this->resolver = $factory->create('255.255.255.255');
176172

177173
$promise = $this->resolver->resolve('google.com');
178174
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
@@ -185,7 +181,7 @@ public function testResolveShouldNotCauseGarbageReferencesWhenUsingInvalidNamese
185181
}
186182

187183
$factory = new Factory();
188-
$this->resolver = $factory->create('255.255.255.255', $this->loop);
184+
$this->resolver = $factory->create('255.255.255.255');
189185

190186
gc_collect_cycles();
191187
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
@@ -203,7 +199,7 @@ public function testResolveCachedShouldNotCauseGarbageReferencesWhenUsingInvalid
203199
}
204200

205201
$factory = new Factory();
206-
$this->resolver = $factory->createCached('255.255.255.255', $this->loop);
202+
$this->resolver = $factory->createCached('255.255.255.255');
207203

208204
gc_collect_cycles();
209205
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
@@ -221,7 +217,7 @@ public function testCancelResolveShouldNotCauseGarbageReferences()
221217
}
222218

223219
$factory = new Factory();
224-
$this->resolver = $factory->create('127.0.0.1', $this->loop);
220+
$this->resolver = $factory->create('127.0.0.1');
225221

226222
gc_collect_cycles();
227223
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
@@ -240,7 +236,7 @@ public function testCancelResolveCachedShouldNotCauseGarbageReferences()
240236
}
241237

242238
$factory = new Factory();
243-
$this->resolver = $factory->createCached('127.0.0.1', $this->loop);
239+
$this->resolver = $factory->createCached('127.0.0.1');
244240

245241
gc_collect_cycles();
246242
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

0 commit comments

Comments
 (0)