Skip to content

Commit 79014db

Browse files
committed
Remove flaky tests relying on DNS
1 parent eadbd86 commit 79014db

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

src/test/php/peer/http/unittest/HttpProxyTest.class.php

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
use lang\IllegalArgumentException;
44
use peer\URL;
55
use peer\http\HttpProxy;
6-
use test\Assert;
7-
use test\{Expect, Test, Values};
8-
9-
/**
10-
* TestCase
11-
*
12-
* @see xp://peer.http.HttpProxy
13-
*/
6+
use test\{Assert, Expect, Test, Values};
7+
148
class HttpProxyTest {
159

1610
#[Test]
@@ -102,34 +96,22 @@ public function exludes_also_work_localhost_special_case() {
10296
Assert::true($proxy->excludes()->contains(new URL('http://127.0.0.1')));
10397
}
10498

105-
/** @return string */
106-
protected function exampleIp() {
107-
static $resolved= null;
108-
109-
if (!$resolved) {
110-
if (!($resolved= dns_get_record('example.com', DNS_A))) {
111-
$this->skip('Cannot resolve example.com (DNS_A)');
112-
}
113-
}
114-
return $resolved[0]['ip'];
115-
}
116-
11799
#[Test]
118100
public function host_excludes_work_with_ips_in_urls() {
119-
$proxy= new HttpProxy('proxy.example.com', 3128, ['example.com']);
120-
Assert::true($proxy->excludes()->contains(new URL('http://'.$this->exampleIp())));
101+
$proxy= new HttpProxy('proxy.example.com', 3128, ['localhost']);
102+
Assert::true($proxy->excludes()->contains(new URL('http://127.0.0.1')));
121103
}
122104

123105
#[Test]
124106
public function ips_in_both_excludes_and_urls_work() {
125-
$proxy= new HttpProxy('proxy.example.com', 3128, [$this->exampleIp()]);
126-
Assert::true($proxy->excludes()->contains(new URL('http://'.$this->exampleIp())));
107+
$proxy= new HttpProxy('proxy.example.com', 3128, ['127.0.0.1']);
108+
Assert::true($proxy->excludes()->contains(new URL('http://127.0.0.1')));
127109
}
128110

129111
#[Test]
130112
public function ip_excludes_work_with_hosts_in_urls() {
131-
$proxy= new HttpProxy('proxy.example.com', 3128, [$this->exampleIp()]);
132-
Assert::true($proxy->excludes()->contains(new URL('http://example.com')));
113+
$proxy= new HttpProxy('proxy.example.com', 3128, ['127.0.0.1']);
114+
Assert::true($proxy->excludes()->contains(new URL('http://localhost')));
133115
}
134116

135117
#[Test, Values([['https://192.168.2.6/', true], ['https://192.168.3.6/', false]])]

0 commit comments

Comments
 (0)