File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
examples/http-client/tests Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -32,5 +32,30 @@ pub static TESTS_PHP_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
3232
3333#[ test]
3434fn 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+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ header ('Content-Type: text/plain ' );
3+ echo "Hello phper! " ;
Original file line number Diff line number Diff line change 2424 ->cookie_store (true )
2525 ->build ();
2626
27- $ response = $ client ->get ("https ://example.com / " )->send ();
27+ $ response = $ client ->get ("http ://localhost:8000 / " )->send ();
2828var_dump ([
2929 "status " => $ response ->status (),
3030 "headers " => $ response ->headers (),
3535 $ client ->get ("file:/// " )->send ();
3636 throw new AssertionError ("no throw exception " );
3737} catch (HttpClientException $ e ) {
38- }
38+ }
You can’t perform that action at this time.
0 commit comments