Skip to content

Commit

Permalink
Added tests for #1779
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Feb 23, 2019
1 parent 9626790 commit 5bc148e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Library/FunctionLike/ReturnType/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function attach($returnType, $definition = null)
$wrong = \is_object($returnType) ? 'instance of '.\get_class($returnType) : \gettype($returnType);

throw new InvalidArgumentException(
\sprintf('Expecting an instance of %s, got %s', TypeInterface::class, $wrong)
sprintf('Expecting an instance of %s, got %s', TypeInterface::class, $wrong)
);
}

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/fixtures/typehints/expected2.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ PHP_FUNCTION(f_TypeHints_retval_nullable_string);
PHP_FUNCTION(f_TypeHints_retval_nullable_boolean);
PHP_FUNCTION(f_TypeHints_retval_nullable_char);
PHP_FUNCTION(f_TypeHints_retval_object_or_scalar);
PHP_FUNCTION(f_TypeHints_retval_array_of_objects);

zend_function_entry php_typehints_functions[] = {
ZEND_NS_NAMED_FE("TypeHints", args, ZEND_FN(f_TypeHints_args), arginfo_f_typehints_args)
Expand All @@ -219,6 +220,7 @@ ZEND_NS_NAMED_FE("TypeHints", retval_nullable_string, ZEND_FN(f_TypeHints_retval
ZEND_NS_NAMED_FE("TypeHints", retval_nullable_boolean, ZEND_FN(f_TypeHints_retval_nullable_boolean), NULL)
ZEND_NS_NAMED_FE("TypeHints", retval_nullable_char, ZEND_FN(f_TypeHints_retval_nullable_char), NULL)
ZEND_NS_NAMED_FE("TypeHints", retval_object_or_scalar, ZEND_FN(f_TypeHints_retval_object_or_scalar), NULL)
ZEND_NS_NAMED_FE("TypeHints", retval_array_of_objects, ZEND_FN(f_TypeHints_retval_array_of_objects), NULL)
ZEND_FE_END

};
Expand Down
9 changes: 9 additions & 0 deletions unit-tests/fixtures/typehints/expected3.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_nullable_char
ZEND_END_ARG_INFO()

PHP_FUNCTION(f_TypeHints_retval_object_or_scalar);
PHP_FUNCTION(f_TypeHints_retval_array_of_objects);
#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_array_of_objects, 0, 0, IS_ARRAY, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_f_typehints_retval_array_of_objects, 0, 0, IS_ARRAY, NULL, 0)
#endif
ZEND_END_ARG_INFO()


zend_function_entry php_typehints_functions[] = {
ZEND_NS_NAMED_FE("TypeHints", args, ZEND_FN(f_TypeHints_args), arginfo_f_typehints_args)
Expand All @@ -322,6 +330,7 @@ ZEND_NS_NAMED_FE("TypeHints", retval_nullable_string, ZEND_FN(f_TypeHints_retval
ZEND_NS_NAMED_FE("TypeHints", retval_nullable_boolean, ZEND_FN(f_TypeHints_retval_nullable_boolean), arginfo_f_typehints_retval_nullable_boolean)
ZEND_NS_NAMED_FE("TypeHints", retval_nullable_char, ZEND_FN(f_TypeHints_retval_nullable_char), arginfo_f_typehints_retval_nullable_char)
ZEND_NS_NAMED_FE("TypeHints", retval_object_or_scalar, ZEND_FN(f_TypeHints_retval_object_or_scalar), NULL)
ZEND_NS_NAMED_FE("TypeHints", retval_array_of_objects, ZEND_FN(f_TypeHints_retval_array_of_objects), arginfo_f_typehints_retval_array_of_objects)
ZEND_FE_END

};
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/fixtures/typehints/expected_retval2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PHP_METHOD(TypeHints_RetVal, retval_int);
PHP_METHOD(TypeHints_RetVal, retval_long);
PHP_METHOD(TypeHints_RetVal, retval_double);
PHP_METHOD(TypeHints_RetVal, retval_array);
PHP_METHOD(TypeHints_RetVal, retval_array_of_objects);
PHP_METHOD(TypeHints_RetVal, retval_collection);
PHP_METHOD(TypeHints_RetVal, retval_retval);
PHP_METHOD(TypeHints_RetVal, retval_nullable_int);
Expand Down Expand Up @@ -44,6 +45,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_long, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_double, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array_of_objects, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_collection, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_retval, NULL, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_int, NULL, ZEND_ACC_PUBLIC)
Expand Down
9 changes: 9 additions & 0 deletions unit-tests/fixtures/typehints/expected_retval3.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PHP_METHOD(TypeHints_RetVal, retval_int);
PHP_METHOD(TypeHints_RetVal, retval_long);
PHP_METHOD(TypeHints_RetVal, retval_double);
PHP_METHOD(TypeHints_RetVal, retval_array);
PHP_METHOD(TypeHints_RetVal, retval_array_of_objects);
PHP_METHOD(TypeHints_RetVal, retval_collection);
PHP_METHOD(TypeHints_RetVal, retval_retval);
PHP_METHOD(TypeHints_RetVal, retval_nullable_int);
Expand Down Expand Up @@ -86,6 +87,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array, 0
#endif
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array_of_objects, 0, 0, IS_ARRAY, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_array_of_objects, 0, 0, IS_ARRAY, NULL, 0)
#endif
ZEND_END_ARG_INFO()

#if PHP_VERSION_ID >= 70200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_typehints_retval_retval_collection, 0, 0, IS_ARRAY, 0)
#else
Expand Down Expand Up @@ -177,6 +185,7 @@ ZEPHIR_INIT_FUNCS(typehints_retval_method_entry) {
PHP_ME(TypeHints_RetVal, retval_long, arginfo_typehints_retval_retval_long, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_double, arginfo_typehints_retval_retval_double, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array, arginfo_typehints_retval_retval_array, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_array_of_objects, arginfo_typehints_retval_retval_array_of_objects, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_collection, arginfo_typehints_retval_retval_collection, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_retval, arginfo_typehints_retval_retval_retval, ZEND_ACC_PUBLIC)
PHP_ME(TypeHints_RetVal, retval_nullable_int, arginfo_typehints_retval_retval_nullable_int, ZEND_ACC_PUBLIC)
Expand Down
10 changes: 10 additions & 0 deletions unit-tests/fixtures/typehints/typehints/retval.zep
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class RetVal {
return [];
}

/** @link https://github.com/phalcon/zephir/issues/1779 */
public function retval_array_of_objects() -> <\stdClass[]> {
return [];
}

public function retval_collection() -> <RetVal[]> {
return [];
}
Expand Down Expand Up @@ -213,3 +218,8 @@ function retval_nullable_char() -> char | null {
function retval_object_or_scalar() -> <\stdClass> | bool {
return false;
}

/** @link https://github.com/phalcon/zephir/issues/1779 */
function retval_array_of_objects() -> <\stdClass[]> {
return [];
}

0 comments on commit 5bc148e

Please sign in to comment.