99// See the Mulan PSL v2 for more details.
1010
1111use phper:: {
12+ arrays:: ZArray ,
1213 classes:: { ClassEntity , Interface , InterfaceEntity , StateClass , Visibility } ,
1314 functions:: { Argument , ReturnType } ,
1415 modules:: Module ,
1516 types:: { ArgumentTypeHint , ReturnTypeHint } ,
1617 values:: ZVal ,
1718} ;
19+ use std:: convert:: Infallible ;
1820
1921const I_FOO : & str = r"IntegrationTest\TypeHints\IFoo" ;
2022
@@ -26,6 +28,45 @@ pub fn integrate(module: &mut Module) {
2628 module. add_class ( make_arg_typehint_class ( ) ) ;
2729 module. add_class ( make_return_typehint_class ( ) ) ;
2830 module. add_class ( make_arg_default_value_class ( ) ) ;
31+ module
32+ . add_function (
33+ "integration_function_return_bool" ,
34+ |_| -> Result < bool , Infallible > { Ok ( true ) } ,
35+ )
36+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) ) ;
37+ module
38+ . add_function (
39+ "integration_function_return_int" ,
40+ |_| -> Result < i64 , Infallible > { Ok ( 42 ) } ,
41+ )
42+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) ) ;
43+ module
44+ . add_function (
45+ "integration_function_return_float" ,
46+ |_| -> Result < f64 , Infallible > { Ok ( 1.234 ) } ,
47+ )
48+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) ) ;
49+ module
50+ . add_function (
51+ "integration_function_return_string" ,
52+ |_| -> Result < & ' static str , Infallible > { Ok ( "phper" ) } ,
53+ )
54+ . return_type ( ReturnType :: new ( ReturnTypeHint :: String ) ) ;
55+ module
56+ . add_function (
57+ "integration_function_return_array" ,
58+ |_| -> Result < ZArray , Infallible > { Ok ( ZArray :: new ( ) ) } ,
59+ )
60+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Array ) ) ;
61+ module
62+ . add_function (
63+ "integration_function_return_mixed" ,
64+ |_| -> Result < ZVal , Infallible > { Ok ( ZVal :: from ( 1.23 ) ) } ,
65+ )
66+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Mixed ) ) ;
67+ module
68+ . add_function ( "integration_function_return_void" , |_| phper:: ok ( ( ) ) )
69+ . return_type ( ReturnType :: new ( ReturnTypeHint :: Void ) ) ;
2970 module
3071 . add_function ( "integration_function_typehints" , |_| phper:: ok ( ( ) ) )
3172 . argument (
@@ -455,11 +496,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
455496 . return_type ( ReturnType :: new ( ReturnTypeHint :: Null ) ) ;
456497
457498 class
458- . add_method (
459- "returnString" ,
460- Visibility :: Public ,
461- move |_, _| phper:: ok ( ( ) ) ,
462- )
499+ . add_method ( "returnString" , Visibility :: Public , move |_, _| {
500+ phper:: ok ( "phper" )
501+ } )
463502 . return_type ( ReturnType :: new ( ReturnTypeHint :: String ) ) ;
464503
465504 class
@@ -469,7 +508,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
469508 . return_type ( ReturnType :: new ( ReturnTypeHint :: String ) . allow_null ( ) ) ;
470509
471510 class
472- . add_method ( "returnBool" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
511+ . add_method ( "returnBool" , Visibility :: Public , move |_, _| {
512+ phper:: ok ( true )
513+ } )
473514 . return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) ) ;
474515
475516 class
@@ -479,7 +520,7 @@ fn make_return_typehint_class() -> ClassEntity<()> {
479520 . return_type ( ReturnType :: new ( ReturnTypeHint :: Bool ) . allow_null ( ) ) ;
480521
481522 class
482- . add_method ( "returnInt" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
523+ . add_method ( "returnInt" , Visibility :: Public , move |_, _| phper:: ok ( 42 ) )
483524 . return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) ) ;
484525
485526 class
@@ -489,7 +530,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
489530 . return_type ( ReturnType :: new ( ReturnTypeHint :: Int ) . allow_null ( ) ) ;
490531
491532 class
492- . add_method ( "returnFloat" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
533+ . add_method ( "returnFloat" , Visibility :: Public , move |_, _| {
534+ phper:: ok ( 1.234 )
535+ } )
493536 . return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) ) ;
494537
495538 class
@@ -499,7 +542,9 @@ fn make_return_typehint_class() -> ClassEntity<()> {
499542 . return_type ( ReturnType :: new ( ReturnTypeHint :: Float ) . allow_null ( ) ) ;
500543
501544 class
502- . add_method ( "returnArray" , Visibility :: Public , move |_, _| phper:: ok ( ( ) ) )
545+ . add_method ( "returnArray" , Visibility :: Public , move |_, _| {
546+ phper:: ok ( ZArray :: new ( ) )
547+ } )
503548 . return_type ( ReturnType :: new ( ReturnTypeHint :: Array ) ) ;
504549
505550 class
0 commit comments