Skip to content

Commit 32c9fce

Browse files
committed
use local web server instead of example.com
1 parent 36b1874 commit 32c9fce

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

examples/http-client/tests/integration.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,30 @@ pub static TESTS_PHP_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
3232

3333
#[test]
3434
fn test_php() {
35+
use std::process::Command;
36+
use std::thread::sleep;
37+
use std::time::Duration;
38+
39+
let router = TESTS_PHP_DIR.join("router.php");
40+
let server = Command::new("php")
41+
.arg("-S")
42+
.arg("127.0.0.1:8000")
43+
.arg("-t")
44+
.arg(TESTS_PHP_DIR.to_str().unwrap())
45+
.arg(router.to_str().unwrap())
46+
.spawn()
47+
.expect("Failed to start PHP built-in server");
48+
49+
struct ServerGuard(std::process::Child);
50+
impl Drop for ServerGuard {
51+
fn drop(&mut self) {
52+
let _ = self.0.kill();
53+
}
54+
}
55+
let _guard = ServerGuard(server);
56+
57+
// Give the server time to start
58+
sleep(Duration::from_secs(1));
59+
3560
test_php_script(&*DYLIB_PATH, TESTS_PHP_DIR.join("test.php"));
36-
}
61+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
header('Content-Type: text/plain');
3+
echo "Hello phper!";

examples/http-client/tests/php/test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
->cookie_store(true)
2525
->build();
2626

27-
$response = $client->get("https://example.com/")->send();
27+
$response = $client->get("http://localhost:8000/")->send();
2828
var_dump([
2929
"status" => $response->status(),
3030
"headers" => $response->headers(),
@@ -35,4 +35,4 @@
3535
$client->get("file:///")->send();
3636
throw new AssertionError("no throw exception");
3737
} catch (HttpClientException $e) {
38-
}
38+
}

0 commit comments

Comments
 (0)