@@ -17,16 +17,30 @@ use phper::{
1717 types:: { ArgumentTypeHint , ReturnTypeHint } ,
1818 values:: ZVal ,
1919} ;
20+ use std:: ffi:: CString ;
2021
2122const I_FOO : & str = r"IntegrationTest\TypeHints\IFoo" ;
2223
2324pub fn integrate ( module : & mut Module ) {
2425 let i_foo = module. add_interface ( make_i_foo_interface ( ) ) ;
2526 let foo_class = module. add_class ( make_foo_class ( i_foo. clone ( ) ) ) ;
26- let _ = module. add_class ( make_b_class ( foo_class. clone ( ) , i_foo. clone ( ) ) ) ;
27- let _ = module. add_class ( make_foo_handler ( ) ) ;
28- let _ = module. add_class ( make_arg_typehint_class ( ) ) ;
29- let _ = module. add_class ( make_return_typehint_class ( ) ) ;
27+ module. add_class ( make_b_class ( foo_class. clone ( ) , i_foo. clone ( ) ) ) ;
28+ module. add_class ( make_foo_handler ( ) ) ;
29+ module. add_class ( make_arg_typehint_class ( ) ) ;
30+ module. add_class ( make_return_typehint_class ( ) ) ;
31+ module. add_class ( make_arg_default_value_class ( ) ) ;
32+ module. add_function ( "integration_function_typehints" , |_| {
33+ phper:: ok ( ( ) )
34+ } ,
35+ )
36+ . argument ( Argument :: by_val ( "s" ) . with_type_hint ( ArgumentTypeHint :: String ) . with_default_value ( CString :: new ( "'foobarbaz'" ) . unwrap ( ) ) )
37+ . argument ( Argument :: by_val ( "i" ) . with_type_hint ( ArgumentTypeHint :: Int ) . with_default_value ( CString :: new ( "42" ) . unwrap ( ) ) )
38+ . argument ( Argument :: by_val ( "f" ) . with_type_hint ( ArgumentTypeHint :: Float ) . with_default_value ( CString :: new ( "7.89" ) . unwrap ( ) ) )
39+ . argument ( Argument :: by_val ( "b" ) . with_type_hint ( ArgumentTypeHint :: Bool ) . with_default_value ( CString :: new ( "true" ) . unwrap ( ) ) )
40+ . argument ( Argument :: by_val ( "a" ) . with_type_hint ( ArgumentTypeHint :: Array ) . with_default_value ( CString :: new ( "['a'=>'b']" ) . unwrap ( ) ) )
41+ . argument ( Argument :: by_val ( "m" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) . with_default_value ( CString :: new ( "1.23" ) . unwrap ( ) ) )
42+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
43+
3044}
3145
3246fn make_i_foo_interface ( ) -> InterfaceEntity {
@@ -123,7 +137,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
123137 let _ = arguments[ 0 ] . expect_z_str ( ) ?. to_str ( ) ?. to_string ( ) ;
124138 phper:: ok ( ( ) )
125139 } )
126- . argument ( Argument :: by_val ( "string_value" ) . with_type_hint ( ArgumentTypeHint :: String ) . nullable ( ) ) ;
140+ . argument ( Argument :: by_val ( "string_value" ) . with_type_hint ( ArgumentTypeHint :: String ) . allow_null ( ) ) ;
127141
128142 // Bool tests
129143 class
@@ -138,7 +152,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
138152 let _ = arguments[ 0 ] . as_bool ( ) ;
139153 phper:: ok ( ( ) )
140154 } )
141- . argument ( Argument :: by_val ( "bool_value" ) . with_type_hint ( ArgumentTypeHint :: Bool ) . nullable ( ) ) ;
155+ . argument ( Argument :: by_val ( "bool_value" ) . with_type_hint ( ArgumentTypeHint :: Bool ) . allow_null ( ) ) ;
142156
143157 class
144158 . add_method ( "testBoolOptional" , Visibility :: Public , move |_, arguments| {
@@ -160,7 +174,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
160174 let _ = arguments[ 0 ] . expect_long ( ) ?;
161175 phper:: ok ( ( ) )
162176 } )
163- . argument ( Argument :: by_val ( "int_value" ) . with_type_hint ( ArgumentTypeHint :: Int ) . nullable ( ) ) ;
177+ . argument ( Argument :: by_val ( "int_value" ) . with_type_hint ( ArgumentTypeHint :: Int ) . allow_null ( ) ) ;
164178
165179 class
166180 . add_method ( "testIntOptional" , Visibility :: Public , move |_, arguments| {
@@ -189,7 +203,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
189203 let _ = arguments[ 0 ] . expect_double ( ) ?;
190204 phper:: ok ( ( ) )
191205 } )
192- . argument ( Argument :: by_val ( "float_value" ) . with_type_hint ( ArgumentTypeHint :: Float ) . nullable ( ) ) ;
206+ . argument ( Argument :: by_val ( "float_value" ) . with_type_hint ( ArgumentTypeHint :: Float ) . allow_null ( ) ) ;
193207
194208 // Array tests
195209 class
@@ -211,7 +225,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
211225 let _ = arguments[ 0 ] . expect_z_arr ( ) ?;
212226 phper:: ok ( ( ) )
213227 } )
214- . argument ( Argument :: by_val ( "array_value" ) . with_type_hint ( ArgumentTypeHint :: Array ) . nullable ( ) ) ;
228+ . argument ( Argument :: by_val ( "array_value" ) . with_type_hint ( ArgumentTypeHint :: Array ) . allow_null ( ) ) ;
215229
216230 // Mixed tests
217231 class
@@ -231,7 +245,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
231245 . add_method ( "testCallableNullable" , Visibility :: Public , move |_, _| {
232246 phper:: ok ( ( ) )
233247 } )
234- . argument ( Argument :: by_val ( "callable_value" ) . with_type_hint ( ArgumentTypeHint :: Callable ) . nullable ( ) ) ;
248+ . argument ( Argument :: by_val ( "callable_value" ) . with_type_hint ( ArgumentTypeHint :: Callable ) . allow_null ( ) ) ;
235249
236250 class
237251 . add_method ( "testCallableOptional" , Visibility :: Public , move |_, _| {
@@ -249,7 +263,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
249263 . add_method ( "testObjectNullable" , Visibility :: Public , move |_, _| {
250264 phper:: ok ( ( ) )
251265 } )
252- . argument ( Argument :: by_val ( "object_value" ) . with_type_hint ( ArgumentTypeHint :: Object ) . nullable ( ) ) ;
266+ . argument ( Argument :: by_val ( "object_value" ) . with_type_hint ( ArgumentTypeHint :: Object ) . allow_null ( ) ) ;
253267
254268 class
255269 . add_method ( "testObjectOptional" , Visibility :: Public , move |_, _| {
@@ -267,7 +281,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
267281 . add_method ( "testIterableNullable" , Visibility :: Public , move |_, _| {
268282 phper:: ok ( ( ) )
269283 } )
270- . argument ( Argument :: by_val ( "iterable_value" ) . with_type_hint ( ArgumentTypeHint :: Iterable ) . nullable ( ) ) ;
284+ . argument ( Argument :: by_val ( "iterable_value" ) . with_type_hint ( ArgumentTypeHint :: Iterable ) . allow_null ( ) ) ;
271285
272286 class
273287 . add_method ( "testIterableOptional" , Visibility :: Public , move |_, _| {
@@ -291,7 +305,7 @@ fn make_arg_typehint_class() ->ClassEntity<()> {
291305 . add_method ( "testClassEntryNullable" , Visibility :: Public , move |_, _| {
292306 phper:: ok ( ( ) )
293307 } )
294- . argument ( Argument :: by_val ( "classentry" ) . with_type_hint ( ArgumentTypeHint :: ClassEntry ( String :: from ( I_FOO ) ) ) . nullable ( ) ) ;
308+ . argument ( Argument :: by_val ( "classentry" ) . with_type_hint ( ArgumentTypeHint :: ClassEntry ( String :: from ( I_FOO ) ) ) . allow_null ( ) ) ;
295309
296310 class
297311 . add_method ( "testClassEntryOptional" , Visibility :: Public , move |_, _| {
@@ -436,5 +450,65 @@ fn make_return_typehint_class() ->ClassEntity<()> {
436450 } )
437451 . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
438452
453+ class
454+ }
455+
456+ fn make_arg_default_value_class ( ) ->ClassEntity < ( ) > {
457+ let mut class = ClassEntity :: new ( r"IntegrationTest\TypeHints\ArgumentDefaultValueTest" ) ;
458+
459+ class
460+ . add_method ( "stringDefault" , Visibility :: Public , move |_, _| {
461+ phper:: ok ( ( ) )
462+ } )
463+ . argument ( Argument :: by_val ( "string_value" ) . with_type_hint ( ArgumentTypeHint :: String ) . with_default_value ( CString :: new ( "'foobarbaz'" ) . unwrap ( ) ) ) ; //NB single quotes!
464+
465+ class
466+ . add_method ( "stringConstantDefault" , Visibility :: Public , move |_, _| {
467+ phper:: ok ( ( ) )
468+ } )
469+ . argument ( Argument :: by_val ( "const_value" ) . with_type_hint ( ArgumentTypeHint :: String ) . with_default_value ( CString :: new ( "PHP_VERSION" ) . unwrap ( ) ) ) ;
470+
471+ class
472+ . add_method ( "boolDefaultTrue" , Visibility :: Public , move |_, _| {
473+ phper:: ok ( ( ) )
474+ } )
475+ . argument ( Argument :: by_val ( "bool_value" ) . with_type_hint ( ArgumentTypeHint :: Bool ) . with_default_value ( CString :: new ( "true" ) . unwrap ( ) ) ) ;
476+
477+ class
478+ . add_method ( "boolDefaultFalse" , Visibility :: Public , move |_, _| {
479+ phper:: ok ( ( ) )
480+ } )
481+ . argument ( Argument :: by_val ( "bool_value" ) . with_type_hint ( ArgumentTypeHint :: Bool ) . with_default_value ( CString :: new ( "false" ) . unwrap ( ) ) ) ;
482+
483+ class
484+ . add_method ( "intDefault" , Visibility :: Public , move |_, _| {
485+ phper:: ok ( ( ) )
486+ } )
487+ . argument ( Argument :: by_val ( "int_value" ) . with_type_hint ( ArgumentTypeHint :: Int ) . with_default_value ( CString :: new ( "42" ) . unwrap ( ) ) ) ;
488+
489+ class
490+ . add_method ( "floatDefault" , Visibility :: Public , move |_, _| {
491+ phper:: ok ( ( ) )
492+ } )
493+ . argument ( Argument :: by_val ( "float_value" ) . with_type_hint ( ArgumentTypeHint :: Float ) . with_default_value ( CString :: new ( "3.14159" ) . unwrap ( ) ) ) ;
494+
495+ class
496+ . add_method ( "arrayDefault" , Visibility :: Public , move |_, _| {
497+ phper:: ok ( ( ) )
498+ } )
499+ . argument ( Argument :: by_val ( "array_value" ) . with_type_hint ( ArgumentTypeHint :: Array ) . with_default_value ( CString :: new ( "['a' => 'b']" ) . unwrap ( ) ) ) ;
500+
501+ class
502+ . add_method ( "iterableDefault" , Visibility :: Public , move |_, _| {
503+ phper:: ok ( ( ) )
504+ } )
505+ . argument ( Argument :: by_val ( "iterable_value" ) . with_type_hint ( ArgumentTypeHint :: Iterable ) . with_default_value ( CString :: new ( "[0 => 1]" ) . unwrap ( ) ) ) ;
506+
507+ class
508+ . add_method ( "mixedDefault" , Visibility :: Public , move |_, _| {
509+ phper:: ok ( ( ) )
510+ } )
511+ . argument ( Argument :: by_val ( "mixed_value" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) . with_default_value ( CString :: new ( "999" ) . unwrap ( ) ) ) ;
512+
439513 class
440514}
0 commit comments