File tree Expand file tree Collapse file tree 4 files changed +42
-9
lines changed
examples/http-client/tests Expand file tree Collapse file tree 4 files changed +42
-9
lines changed Original file line number Diff line number Diff line change @@ -78,17 +78,13 @@ jobs:
7878 sudo rm -f /usr/sbin/php-fpm
7979 sudo ln -s /usr/sbin/php-fpm${{ matrix.php-version }} /usr/sbin/php-fpm
8080
81- - name : Setup php-fpm for Macos
82- if : matrix.os == 'macos-14'
83- run : |
84- brew install php@${{ matrix.php-version }}
85- echo "/opt/homebrew/opt/php@${{ matrix.php-version }}/bin" >> "$GITHUB_PATH"
86- echo "/opt/homebrew/opt/php@${{ matrix.php-version }}/sbin" >> "$GITHUB_PATH"
87-
8881 - name : PHP version
8982 run : |
83+ which php
9084 php --version
85+ which php-fpm
9186 php-fpm --version
87+ which php-config
9288 php-config || true
9389
9490 [[ `php --version` == PHP\ ${{ matrix.php-version }}.* ]] || exit 1;
Original file line number Diff line number Diff line change @@ -32,5 +32,28 @@ pub static TESTS_PHP_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
3232
3333#[ test]
3434fn test_php ( ) {
35+ use std:: { process:: Command , thread:: sleep, time:: Duration } ;
36+
37+ let router = TESTS_PHP_DIR . join ( "router.php" ) ;
38+ let server = Command :: new ( "php" )
39+ . arg ( "-S" )
40+ . arg ( "127.0.0.1:8000" )
41+ . arg ( "-t" )
42+ . arg ( TESTS_PHP_DIR . to_str ( ) . unwrap ( ) )
43+ . arg ( router. to_str ( ) . unwrap ( ) )
44+ . spawn ( )
45+ . expect ( "Failed to start PHP built-in server" ) ;
46+
47+ struct ServerGuard ( std:: process:: Child ) ;
48+ impl Drop for ServerGuard {
49+ fn drop ( & mut self ) {
50+ let _ = self . 0 . kill ( ) ;
51+ }
52+ }
53+ let _guard = ServerGuard ( server) ;
54+
55+ // Give the server time to start
56+ sleep ( Duration :: from_secs ( 1 ) ) ;
57+
3558 test_php_script ( & * DYLIB_PATH , TESTS_PHP_DIR . join ( "test.php" ) ) ;
3659}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // Copyright (c) 2022 PHPER Framework Team
4+ // PHPER is licensed under Mulan PSL v2.
5+ // You can use this software according to the terms and conditions of the Mulan
6+ // PSL v2. You may obtain a copy of Mulan PSL v2 at:
7+ // http://license.coscl.org.cn/MulanPSL2
8+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
9+ // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
10+ // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11+ // See the Mulan PSL v2 for more details.
12+
13+ header ('Content-Type: text/plain ' );
14+ 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