11#![ cfg_attr( windows, feature( abi_vectorcall) ) ]
22extern crate ext_php_rs;
33
4+ #[ cfg( feature = "embed" ) ]
5+ use std:: ffi:: c_char;
46#[ cfg( feature = "embed" ) ]
57use ext_php_rs:: builders:: SapiBuilder ;
68#[ cfg( feature = "embed" ) ]
@@ -14,10 +16,29 @@ use ext_php_rs::prelude::*;
1416#[ cfg( feature = "embed" ) ]
1517use ext_php_rs:: zend:: try_catch;
1618
19+ #[ cfg( feature = "embed" ) ]
20+ static mut LAST_OUTPUT : String = String :: new ( ) ;
21+
22+ #[ cfg( feature = "embed" ) ]
23+ extern "C" fn output_tester ( str : * const c_char , str_length : usize ) -> usize {
24+ let char = unsafe { std:: slice:: from_raw_parts ( str as * const u8 , str_length) } ;
25+ let string = String :: from_utf8_lossy ( char) ;
26+
27+ println ! ( "{}" , string) ;
28+
29+ unsafe {
30+ LAST_OUTPUT = string. to_string ( ) ;
31+ } ;
32+
33+ str_length
34+ }
35+
1736#[ test]
1837#[ cfg( feature = "embed" ) ]
1938fn test_sapi ( ) {
20- let builder = SapiBuilder :: new ( "test" , "Test" ) ;
39+ let mut builder = SapiBuilder :: new ( "test" , "Test" ) ;
40+ builder = builder. ub_write_function ( output_tester) ;
41+
2142 let sapi = builder. build ( ) . unwrap ( ) . into_raw ( ) ;
2243 let module = get_module ( ) ;
2344
@@ -50,6 +71,10 @@ fn test_sapi() {
5071 let string = zval. string ( ) . unwrap ( ) ;
5172
5273 assert_eq ! ( string. to_string( ) , "Hello, foo!" ) ;
74+
75+ let result = Embed :: eval ( "var_dump($foo);" ) ;
76+
77+ assert ! ( result. is_ok( ) ) ;
5378 } ,
5479 true ,
5580 ) ;
@@ -58,6 +83,10 @@ fn test_sapi() {
5883 php_request_shutdown ( std:: ptr:: null_mut ( ) ) ;
5984 }
6085
86+ unsafe {
87+ assert_eq ! ( LAST_OUTPUT , "string(11) \" Hello, foo!\" \n " ) ;
88+ }
89+
6190 unsafe {
6291 php_module_shutdown ( ) ;
6392 }
0 commit comments