summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest/it_url.t48
-rw-r--r--test/it_url_server.php5
-rwxr-xr-xtest/it_url_slow.t14
3 files changed, 34 insertions, 33 deletions
diff --git a/test/it_url.t b/test/it_url.t
index a7e1ce3..02fe45c 100755
--- a/test/it_url.t
+++ b/test/it_url.t
@@ -136,7 +136,7 @@ require 'it_url_server.php';
is(it_url::is_reachable('http://www.gna.ch/'), true, "is_reachable('http://www.gna.ch/')");
is(it_url::is_reachable('http://www.search.ch/not_found'), false, "is_reachable('http://www.search.ch/not_found')");
is(it_url::is_reachable('http://bogus.url'), false, "is_reachable('http://bogus.url')");
-is(it_url::is_reachable(U('http://localhost:8000/redirect_loop', ['num' => 40])), false, "redirect loop is not reachable");
+is(it_url::is_reachable(U("http://$host/redirect_loop", ['num' => 40])), false, "redirect loop is not reachable");
$response = it_url::get(['url' => 'http://www.gna.ch/', 'assoc' => true]);
ok(
@@ -162,7 +162,7 @@ ok(
handle_server(
is(
- it_url::get('http://localhost:8000/'),
+ it_url::get("http://$host/"),
"Testserver root output",
'it_url::get() static call with port'
)
@@ -170,7 +170,7 @@ handle_server(
handle_server(
is(
- it_url::get('//localhost:8000/'),
+ it_url::get("//$host/"),
"Testserver root output",
'it_url::get() static call with port but no protocol'
)
@@ -178,7 +178,7 @@ handle_server(
handle_server(
is(
- it_url::get(['url' => 'http://localhost:8000/', 'maxlength' => 100]),
+ it_url::get(['url' => "http://$host/", 'maxlength' => 100]),
"Testserver root output",
'it_url::get() static call with port and maxlength'
)
@@ -186,7 +186,7 @@ handle_server(
handle_server(
is(
- it_url::get(['url' => 'http://localhost:8000/', 'maxlength' => 5, 'it_error' => false]),
+ it_url::get(['url' => "http://$host/", 'maxlength' => 5, 'it_error' => false]),
false,
'it_url::get() static call with port and too small maxlength'
)
@@ -194,7 +194,7 @@ handle_server(
handle_server(
is(
- it_url::get('http://localhost:8000/temp_redirect'),
+ it_url::get("http://$host/temp_redirect"),
"Testserver output after temporary redirect",
'it_url::get() follows temproary redirect'
)
@@ -202,7 +202,7 @@ handle_server(
handle_server(
is(
- it_url::get('http://localhost:8000/perm_redirect'),
+ it_url::get("http://$host/perm_redirect"),
"Testserver output after permanent redirect",
'it_url::get() follows permanent redirect'
)
@@ -210,7 +210,7 @@ handle_server(
handle_server(
is(
- it_url::get(['url' => 'http://localhost:8000/relative_redirect', 'it_error' => false]),
+ it_url::get(['url' => "http://$host/relative_redirect", 'it_error' => false]),
"Testserver output after relative redirect",
'it_url::get() follows relative redirect correctly'
)
@@ -218,7 +218,7 @@ handle_server(
handle_server(
is(
- it_url::get('http://localhost:8000/nohost_redirect'),
+ it_url::get("http://$host/nohost_redirect"),
"Testserver output after nohost redirect",
'it_url::get() follows redirect without host correctly'
)
@@ -226,7 +226,7 @@ handle_server(
handle_server(
is(
- it_url::get('http://localhost:8000/created_redirect'),
+ it_url::get("http://$host/created_redirect"),
"Testserver output *before* created redirect",
'it_url::get() does not follow Location of 201 (Created) result'
)
@@ -234,7 +234,7 @@ handle_server(
$output = handle_server(
ok(
- !it_url::get(['url' => U('http://localhost:8000/redirect_loop', ['num' => 40]), 'it_error' => false]),
+ !it_url::get(['url' => U("http://$host/redirect_loop", ['num' => 40]), 'it_error' => false]),
'it_url::get() handles redirect loop'
)
);
@@ -247,7 +247,7 @@ if (!ok(
$output = handle_server(
ok(
- !it_url::get(['url' => 'http://localhost:8000/does_not_exist', 'retries' => 4]),
+ !it_url::get(['url' => "http://$host/does_not_exist", 'retries' => 4]),
'it_url::get() on 404'
)
);
@@ -259,7 +259,7 @@ if (!ok(
$output = handle_server(
ok(
- !it_url::get(['url' => 'http://localhost:8000/repeat?num=0', 'retries' => 4]),
+ !it_url::get(['url' => "http://$host/repeat?num=0", 'retries' => 4]),
'it_url::get() on empty page'
)
);
@@ -271,7 +271,7 @@ if (!ok(
$output = handle_server(
is(
- it_url::get(U('http://localhost:8000/empty')),
+ it_url::get(U("http://$host/empty")),
'',
'it_url::get() explicit empty result'
)
@@ -284,15 +284,15 @@ if (!ok(
handle_server(
is(
- it_url::get(U('http://localhost:8000/get_server_value', ['key' => 'HTTP_HOST'])),
- 'localhost:8000',
+ it_url::get(U("http://$host/get_server_value", ['key' => 'HTTP_HOST'])),
+ $host,
'it_url::get() sets correct Host header'
)
);
handle_server(
is(
- it_url::get(U('http://localhost:8000/get_server_value', ['key' => 'HTTP_ACCEPT_LANGUAGE'])),
+ it_url::get(U("http://$host/get_server_value", ['key' => 'HTTP_ACCEPT_LANGUAGE'])),
T_lang(),
'it_url::get() sets correct Accept-Language header'
)
@@ -300,14 +300,14 @@ handle_server(
handle_server(
ok(
- it::match('Mozilla', it_url::get(U('http://localhost:8000/get_server_value', ['key' => 'HTTP_USER_AGENT']))),
+ it::match('Mozilla', it_url::get(U("http://$host/get_server_value", ['key' => 'HTTP_USER_AGENT']))),
'it_url::get() sets User-Agent containing Mozilla'
)
);
handle_server(
is(
- it_url::get(U('http://user:password@localhost:8000/get_server_value', ['key' => 'PHP_AUTH_USER'])),
+ it_url::get(U("http://user:password@$host/get_server_value", ['key' => 'PHP_AUTH_USER'])),
'user',
'it_url::get() basic authentication user'
)
@@ -315,7 +315,7 @@ handle_server(
handle_server(
is(
- it_url::get(U('http://user:password@localhost:8000/get_server_value', ['key' => 'PHP_AUTH_PW'])),
+ it_url::get(U("http://user:password@$host/get_server_value", ['key' => 'PHP_AUTH_PW'])),
'password',
'it_url::get() basic authentication password'
)
@@ -328,20 +328,20 @@ is(count($pages), 2, 'it_url::get_multi no additional array elements');
handle_server(
is(
- it_url::get('http://localhost:8000/maybe_error?chance=0'),
+ it_url::get("http://$host/maybe_error?chance=0"),
"success"
),
is(
- it_url::get('http://localhost:8000/maybe_error?chance=100'),
+ it_url::get("http://$host/maybe_error?chance=100"),
"failure"
),
is(
- it_url::get(['url' => 'http://localhost:8000/maybe_error?chance=10', 'retries' => 10]),
+ it_url::get(['url' => "http://$host/maybe_error?chance=10", 'retries' => 10]),
"success",
"Retry on sporadically failing url in ::get"
),
is(
- it_url::get_multi(['urls' => ['http://localhost:8000/maybe_error?chance=10'], 'retries' => 10]),
+ it_url::get_multi(['urls' => ["http://$host/maybe_error?chance=10"], 'retries' => 10]),
["success"],
"Retry on sporadically failing url in ::get_multi"
)
diff --git a/test/it_url_server.php b/test/it_url_server.php
index b113be1..c832ee5 100644
--- a/test/it_url_server.php
+++ b/test/it_url_server.php
@@ -1,7 +1,8 @@
<?php
+$host = 'localhost:' . rand(8000,8060);
$server = proc_open(
- 'php -S localhost:8000 -q ' . dirname($_SERVER['PHP_SELF']) . '/it_url.testserver.php',
- array(0 => fopen('/dev/null', 'r'), 1 => fopen('/dev/null', 'w'), 2 => array('pipe', 'w')),
+ "php -S $host -q " . dirname($_SERVER['PHP_SELF']) . '/it_url.testserver.php',
+ array(0 => it::fopen('/dev/null', 'r'), 1 => it::fopen('/dev/null', 'w'), 2 => array('pipe', 'w')),
$pipes
);
register_shutdown_function(
diff --git a/test/it_url_slow.t b/test/it_url_slow.t
index 28b1bf9..59afe7e 100755
--- a/test/it_url_slow.t
+++ b/test/it_url_slow.t
@@ -9,7 +9,7 @@ require 'it_url_server.php';
handle_server(
is(
- it_url::get('http://localhost:8000/short_sleep'),
+ it_url::get("http://$host/short_sleep"),
"Testserver output after short sleep",
'it_url::get() receives full output after short sleep'
)
@@ -17,7 +17,7 @@ handle_server(
$start = microtime(true);
$res = is(
- it_url::get(['url' => 'http://localhost:8000/long_sleep', 'timeout' => 4, 'retries' => 0, 'it_error' => false]),
+ it_url::get(['url' => "http://$host/long_sleep", 'timeout' => 4, 'retries' => 0, 'it_error' => false]),
false,
'it_url::get() fails after timeout seconds with no output'
);
@@ -33,7 +33,7 @@ if (!$res || !$res2)
handle_server(
is(
- it_url::get('http://localhost:8000/slow_response'),
+ it_url::get("http://$host/slow_response"),
implode('', it::map('"Testserver slow output $v\n"', range(0, 5))),
'it_url::get() waits for slow response with continuous output'
)
@@ -41,7 +41,7 @@ handle_server(
$start = microtime(true);
$res = ok(
- !it_url::get(['url' => 'http://localhost:8000/slow_response', 'totaltimeout' => 5, 'retries' => 0, 'it_error' => false]),
+ !it_url::get(['url' => "http://$host/slow_response", 'totaltimeout' => 5, 'retries' => 0, 'it_error' => false]),
'it_url::get() fails for response slower than totaltimeout'
);
$res2 = is(
@@ -55,7 +55,7 @@ if (!$res || !$res2)
$start = microtime(true);
$res = ok(
- !it_url::get(['url' => 'http://localhost:8000/slow_response', 'maxlength' => 10, 'retries' => 0, 'it_error' => false]),
+ !it_url::get(['url' => "http://$host/slow_response", 'maxlength' => 10, 'retries' => 0, 'it_error' => false]),
'it_url::get() fails for response larger than maxlength'
);
$res2 = is(
@@ -69,12 +69,12 @@ if (!$res || !$res2)
handle_server(
ok(
- it_url::get(U('http://localhost:8000/repeat', ['string' => "abc", 'num' => 1024 * 1024])) == str_repeat("abc", 1024 * 1024),
+ it_url::get(U("http://$host/repeat", ['string' => "abc", 'num' => 1024 * 1024])) == str_repeat("abc", 1024 * 1024),
'it_url::get() handles large response'
)
);
$start = microtime(true);
-it_url::get_multi(['urls' => ['slow' => 'http://localhost:8000/long_sleep', 'fast' => ['url' => 'http://search.ch/', 'handler' => function () {return true;}]]]);
+it_url::get_multi(['urls' => ['slow' => "http://$host/long_sleep", 'fast' => ['url' => 'http://search.ch/', 'handler' => function () {return true;}]]]);
ok(intval(microtime(true) - $start) < 4, 'get_multi with handler aborts after fast request');
$output = server_output();