From c0dd5e8a9c4ac5a7c3fc6fec384569f30e7f21e3 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 19 Sep 2021 00:17:36 +0100 Subject: [PATCH] #2276 - Add support for `mixed` in return types --- Library/ArgInfoDefinition.php | 10 +- Library/ClassMethod.php | 2 +- Library/Exception/InvalidTypeException.php | 4 +- Library/Statements/ReturnStatement.php | 38 +++--- ext/config.m4 | 3 +- ext/config.w32 | 3 +- ext/stub.c | 2 + ext/stub.h | 1 + ext/stub/types/mixedtype.zep.c | 130 +++++++++++++++++++++ ext/stub/types/mixedtype.zep.h | 91 +++++++++++++++ stub/types/mixedtype.zep | 55 +++++++++ tests/Extension/Types/MixedTest.php | 45 +++++++ 12 files changed, 358 insertions(+), 26 deletions(-) create mode 100644 ext/stub/types/mixedtype.zep.c create mode 100644 ext/stub/types/mixedtype.zep.h create mode 100644 stub/types/mixedtype.zep create mode 100644 tests/Extension/Types/MixedTest.php diff --git a/Library/ArgInfoDefinition.php b/Library/ArgInfoDefinition.php index 14d69169ed..76c54051dd 100644 --- a/Library/ArgInfoDefinition.php +++ b/Library/ArgInfoDefinition.php @@ -31,7 +31,7 @@ class ArgInfoDefinition /** * @var string */ - private string $name = ''; + private string $name; /** * @var ClassMethodParameters|null @@ -61,18 +61,18 @@ class ArgInfoDefinition /** * ArgInfoDefinition constructor. * - * @param $name + * @param string $name * @param ClassMethod $functionLike * @param CodePrinter $codePrinter * @param CompilationContext $compilationContext - * @param false $returnByRef + * @param bool $returnByRef */ public function __construct( - $name, + string $name, ClassMethod $functionLike, CodePrinter $codePrinter, CompilationContext $compilationContext, - $returnByRef = false + bool $returnByRef = false ) { $this->functionLike = $functionLike; $this->codePrinter = $codePrinter; diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index fd4acb45cc..1fb7583e07 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -650,7 +650,7 @@ public function areReturnTypesNullCompatible(): bool */ public function areReturnTypesIntCompatible(): bool { - $types = ['int', 'uint', 'char', 'uchar', 'long', 'ulong', 'mixed']; + $types = ['int', 'uint', 'char', 'uchar', 'long', 'ulong']; foreach ($this->returnTypes as $returnType => $definition) { if (in_array($returnType, $types)) { diff --git a/Library/Exception/InvalidTypeException.php b/Library/Exception/InvalidTypeException.php index be1542a788..fad4b82b46 100644 --- a/Library/Exception/InvalidTypeException.php +++ b/Library/Exception/InvalidTypeException.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Exception; final class InvalidTypeException extends CompilerException @@ -19,7 +21,7 @@ final class InvalidTypeException extends CompilerException * @param string $type * @param array|null $expression */ - public function __construct($type, array $expression = null) + public function __construct(string $type, array $expression = null) { $message = sprintf( 'Returning type: %s but this type is not compatible with return-type hints declared in the method', diff --git a/Library/Statements/ReturnStatement.php b/Library/Statements/ReturnStatement.php index 37f7f28d03..65877d5d32 100644 --- a/Library/Statements/ReturnStatement.php +++ b/Library/Statements/ReturnStatement.php @@ -11,13 +11,16 @@ namespace Zephir\Statements; -use function Zephir\add_slashes; +use ReflectionException; use Zephir\CompilationContext; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Exception\InvalidTypeException; use Zephir\Expression; use Zephir\Types; +use function Zephir\add_slashes; + /** * ReturnStatement. * @@ -28,9 +31,10 @@ final class ReturnStatement extends StatementAbstract /** * @param CompilationContext $compilationContext * - * @throws CompilerException + * @throws Exception + * @throws ReflectionException */ - public function compile(CompilationContext $compilationContext) + public function compile(CompilationContext $compilationContext): void { $statement = $this->statement; @@ -50,14 +54,14 @@ public function compile(CompilationContext $compilationContext) ); } - /* + /** * Use return member for properties on this */ if ('property-access' == $statement['expr']['type']) { if ('variable' == $statement['expr']['left']['type']) { if ('this' == $statement['expr']['left']['value']) { if ('variable' == $statement['expr']['right']['type']) { - /* + /** * If the property is accessed on 'this', we check if the property does exist. */ $property = $statement['expr']['right']['value']; @@ -82,7 +86,7 @@ public function compile(CompilationContext $compilationContext) } } - /* + /** * Fetches return_value and tries to return the value directly there. */ $variable = $compilationContext->symbolTable->getVariable('return_value'); @@ -92,13 +96,13 @@ public function compile(CompilationContext $compilationContext) $expr->setReadOnly(true); $resolvedExpr = $expr->compile($compilationContext); - /* + /** * Here we check if the variable returns a compatible type according to its type hints */ if ($currentMethod->hasReturnTypes()) { switch ($resolvedExpr->getType()) { case Types::T_NULL: - if (false == $currentMethod->areReturnTypesNullCompatible()) { + if (!$currentMethod->areReturnTypesNullCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; @@ -109,26 +113,26 @@ public function compile(CompilationContext $compilationContext) case Types::T_ULONG: case Types::T_CHAR: case Types::T_UCHAR: - if (false == $currentMethod->areReturnTypesIntCompatible()) { + if (!$currentMethod->areReturnTypesIntCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_BOOL: - if (false == $currentMethod->areReturnTypesBoolCompatible()) { + if (!$currentMethod->areReturnTypesBoolCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_DOUBLE: - if (false == $currentMethod->areReturnTypesDoubleCompatible()) { + if (!$currentMethod->areReturnTypesDoubleCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_STRING: case Types::T_ISTRING: - if (false == $currentMethod->areReturnTypesStringCompatible()) { + if (!$currentMethod->areReturnTypesStringCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; @@ -147,26 +151,26 @@ public function compile(CompilationContext $compilationContext) case Types::T_ULONG: case Types::T_CHAR: case Types::T_UCHAR: - if (false == $currentMethod->areReturnTypesIntCompatible()) { + if (!$currentMethod->areReturnTypesIntCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_DOUBLE: - if (false == $currentMethod->areReturnTypesDoubleCompatible()) { + if (!$currentMethod->areReturnTypesDoubleCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_STRING: case Types::T_ISTRING: - if (false == $currentMethod->areReturnTypesStringCompatible()) { + if (!$currentMethod->areReturnTypesStringCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; case Types::T_BOOL: - if (false == $currentMethod->areReturnTypesBoolCompatible()) { + if (!$currentMethod->areReturnTypesBoolCompatible() && !$currentMethod->isMixed()) { throw new InvalidTypeException($resolvedExpr->getType(), $statement['expr']); } break; @@ -314,7 +318,7 @@ public function compile(CompilationContext $compilationContext) return; } - /* + /** * Return without an expression */ $codePrinter->output('RETURN_MM_NULL();'); diff --git a/ext/config.m4 b/ext/config.m4 index cceffb6578..8552cc50ac 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -212,6 +212,7 @@ if test "$PHP_STUB" = "yes"; then stub/typehinting/testabstract.zep.c stub/typeinstances.zep.c stub/typeoff.zep.c + stub/types/mixedtype.zep.c stub/unknownclass.zep.c stub/unsettest.zep.c stub/usetest.zep.c @@ -232,7 +233,7 @@ if test "$PHP_STUB" = "yes"; then stub/13__closure.zep.c " PHP_NEW_EXTENSION(stub, $stub_sources, $ext_shared,, ) PHP_ADD_BUILD_DIR([$ext_builddir/kernel/]) - for dir in "stub stub/bench stub/builtin stub/constructors stub/flow stub/globals stub/globals/session stub/integration/psr stub/integration/psr/http/message stub/interfaces stub/invokes stub/issue2165 stub/mcall stub/namespaces stub/namespaces/a/b stub/oo stub/oo/extend stub/oo/extend/db stub/oo/extend/db/query stub/oo/extend/db/query/placeholder stub/oo/extend/spl stub/oo/scopes stub/ooimpl stub/optimizers stub/properties stub/requires stub/router stub/typehinting"; do + for dir in "stub stub/bench stub/builtin stub/constructors stub/flow stub/globals stub/globals/session stub/integration/psr stub/integration/psr/http/message stub/interfaces stub/invokes stub/issue2165 stub/mcall stub/namespaces stub/namespaces/a/b stub/oo stub/oo/extend stub/oo/extend/db stub/oo/extend/db/query stub/oo/extend/db/query/placeholder stub/oo/extend/spl stub/oo/scopes stub/ooimpl stub/optimizers stub/properties stub/requires stub/router stub/typehinting stub/types"; do PHP_ADD_BUILD_DIR([$ext_builddir/$dir]) done PHP_SUBST(STUB_SHARED_LIBADD) diff --git a/ext/config.w32 b/ext/config.w32 index 12199ac28c..7cc2da4067 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -37,7 +37,8 @@ if (PHP_STUB != "no") { ADD_SOURCES(configure_module_dirname + "/stub/optimizers", "isscalar.zep.c acos.zep.c arraymerge.zep.c asin.zep.c cos.zep.c createarray.zep.c ldexp.zep.c sin.zep.c sqrt.zep.c strreplace.zep.c substr.zep.c tan.zep.c", "stub"); ADD_SOURCES(configure_module_dirname + "/stub/requires", "external3.zep.c", "stub"); ADD_SOURCES(configure_module_dirname + "/stub/router", "exception.zep.c route.zep.c", "stub"); - ADD_SOURCES(configure_module_dirname + "/stub/typehinting", "testabstract.zep.c", "stub"); + ADD_SOURCES(configure_module_dirname + "/stub/typehinting", "testabstract.zep.c", "stub"); + ADD_SOURCES(configure_module_dirname + "/stub/types", "mixedtype.zep.c", "stub"); ADD_FLAG("CFLAGS_STUB", "/D ZEPHIR_RELEASE /Oi /Ot /Oy /Ob2 /Gs /GF /Gy /GL"); ADD_FLAG("CFLAGS", "/D ZEPHIR_RELEASE /Oi /Ot /Oy /Ob2 /Gs /GF /Gy /GL"); ADD_FLAG("LDFLAGS", "/LTCG"); diff --git a/ext/stub.c b/ext/stub.c index e1f353ba99..c4e86bcae8 100644 --- a/ext/stub.c +++ b/ext/stub.c @@ -240,6 +240,7 @@ zend_class_entry *stub_trytest_ce; zend_class_entry *stub_typehinting_testabstract_ce; zend_class_entry *stub_typeinstances_ce; zend_class_entry *stub_typeoff_ce; +zend_class_entry *stub_types_mixedtype_ce; zend_class_entry *stub_unknownclass_ce; zend_class_entry *stub_unsettest_ce; zend_class_entry *stub_usetest_ce; @@ -465,6 +466,7 @@ static PHP_MINIT_FUNCTION(stub) ZEPHIR_INIT(Stub_TypeHinting_TestAbstract); ZEPHIR_INIT(Stub_TypeInstances); ZEPHIR_INIT(Stub_Typeoff); + ZEPHIR_INIT(Stub_Types_MixedType); ZEPHIR_INIT(Stub_UnknownClass); ZEPHIR_INIT(Stub_Unsettest); ZEPHIR_INIT(Stub_UseTest); diff --git a/ext/stub.h b/ext/stub.h index da8ea50cb6..cf7b456b20 100644 --- a/ext/stub.h +++ b/ext/stub.h @@ -207,6 +207,7 @@ #include "stub/typehinting/testabstract.zep.h" #include "stub/typeinstances.zep.h" #include "stub/typeoff.zep.h" +#include "stub/types/mixedtype.zep.h" #include "stub/unknownclass.zep.h" #include "stub/unsettest.zep.h" #include "stub/usetest.zep.h" diff --git a/ext/stub/types/mixedtype.zep.c b/ext/stub/types/mixedtype.zep.c new file mode 100644 index 0000000000..3659d7286b --- /dev/null +++ b/ext/stub/types/mixedtype.zep.c @@ -0,0 +1,130 @@ + +#ifdef HAVE_CONFIG_H +#include "../../ext_config.h" +#endif + +#include +#include "../../php_ext.h" +#include "../../ext.h" + +#include +#include +#include + +#include "kernel/main.h" +#include "kernel/object.h" +#include "kernel/operators.h" +#include "kernel/memory.h" + + +ZEPHIR_INIT_CLASS(Stub_Types_MixedType) +{ + ZEPHIR_REGISTER_CLASS(Stub\\Types, MixedType, stub, types_mixedtype, stub_types_mixedtype_method_entry, 0); + + return SUCCESS; +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedObject) +{ + zval *this_ptr = getThis(); + + + + object_init(return_value); + return; +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedArray) +{ + zval *this_ptr = getThis(); + + + + array_init(return_value); + return; +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedString) +{ + zval *this_ptr = getThis(); + + + + RETURN_STRING("mixed string"); +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedInt) +{ + zval *this_ptr = getThis(); + + + + RETURN_LONG(1); +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedFloat) +{ + zval *this_ptr = getThis(); + + + + RETURN_DOUBLE(3.14); +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedBool) +{ + zval *this_ptr = getThis(); + + + + RETURN_BOOL(1); +} + +PHP_METHOD(Stub_Types_MixedType, returnMixedNull) +{ + zval *this_ptr = getThis(); + + + + RETURN_NULL(); +} + +PHP_METHOD(Stub_Types_MixedType, returnMixed74) +{ + zval *diff_param = NULL; + zend_bool diff; + zval *this_ptr = getThis(); + +#if PHP_VERSION_ID >= 80000 + bool is_null_true = 1; + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(diff) + ZEND_PARSE_PARAMETERS_END(); +#endif + + + zephir_fetch_params_without_memory_grow(0, 1, &diff_param); + if (!diff_param) { + diff = 0; + } else { + diff = zephir_get_boolval(diff_param); + } + + + if (diff) { + RETURN_STRING("string"); + } + object_init(return_value); + return; +} + +PHP_METHOD(Stub_Types_MixedType, returnMultiButAlwaysMixed) +{ + zval *this_ptr = getThis(); + + + + RETURN_STRING("IS_MIXED in header"); +} + diff --git a/ext/stub/types/mixedtype.zep.h b/ext/stub/types/mixedtype.zep.h new file mode 100644 index 0000000000..929cb05366 --- /dev/null +++ b/ext/stub/types/mixedtype.zep.h @@ -0,0 +1,91 @@ + +extern zend_class_entry *stub_types_mixedtype_ce; + +ZEPHIR_INIT_CLASS(Stub_Types_MixedType); + +PHP_METHOD(Stub_Types_MixedType, returnMixedObject); +PHP_METHOD(Stub_Types_MixedType, returnMixedArray); +PHP_METHOD(Stub_Types_MixedType, returnMixedString); +PHP_METHOD(Stub_Types_MixedType, returnMixedInt); +PHP_METHOD(Stub_Types_MixedType, returnMixedFloat); +PHP_METHOD(Stub_Types_MixedType, returnMixedBool); +PHP_METHOD(Stub_Types_MixedType, returnMixedNull); +PHP_METHOD(Stub_Types_MixedType, returnMixed74); +PHP_METHOD(Stub_Types_MixedType, returnMultiButAlwaysMixed); + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedobject, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedobject, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedarray, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedarray, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedstring, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedstring, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedint, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedint, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedfloat, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedfloat, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedbool, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixedbool, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixednull, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixednull, 0, 0, IS_NULL, 0) +#endif +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixed74, 0, 0, IS_MIXED, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_types_mixedtype_returnmixed74, 0, 0, IS_NULL, 0) +#endif + ZEND_ARG_TYPE_INFO(0, diff, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_types_mixedtype_returnmultibutalwaysmixed, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEPHIR_INIT_FUNCS(stub_types_mixedtype_method_entry) { + PHP_ME(Stub_Types_MixedType, returnMixedObject, arginfo_stub_types_mixedtype_returnmixedobject, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedArray, arginfo_stub_types_mixedtype_returnmixedarray, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedString, arginfo_stub_types_mixedtype_returnmixedstring, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedInt, arginfo_stub_types_mixedtype_returnmixedint, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedFloat, arginfo_stub_types_mixedtype_returnmixedfloat, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedBool, arginfo_stub_types_mixedtype_returnmixedbool, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixedNull, arginfo_stub_types_mixedtype_returnmixednull, ZEND_ACC_PUBLIC) + PHP_ME(Stub_Types_MixedType, returnMixed74, arginfo_stub_types_mixedtype_returnmixed74, ZEND_ACC_PUBLIC) +#if PHP_VERSION_ID >= 80000 + PHP_ME(Stub_Types_MixedType, returnMultiButAlwaysMixed, arginfo_stub_types_mixedtype_returnmultibutalwaysmixed, ZEND_ACC_PUBLIC) +#else + PHP_ME(Stub_Types_MixedType, returnMultiButAlwaysMixed, NULL, ZEND_ACC_PUBLIC) +#endif + PHP_FE_END +}; diff --git a/stub/types/mixedtype.zep b/stub/types/mixedtype.zep new file mode 100644 index 0000000000..6553360440 --- /dev/null +++ b/stub/types/mixedtype.zep @@ -0,0 +1,55 @@ + +namespace Stub\Types; + +class MixedType +{ + public function returnMixedObject() -> mixed + { + return new \stdClass(); + } + + public function returnMixedArray() -> mixed + { + return []; + } + + public function returnMixedString() -> mixed + { + return "mixed string"; + } + + public function returnMixedInt() -> mixed + { + return 1; + } + + public function returnMixedFloat() -> mixed + { + return 3.14; + } + + public function returnMixedBool() -> mixed + { + return true; + } + + public function returnMixedNull() -> mixed + { + return null; + } + + public function returnMixed74(bool diff = false) -> mixed + { + if (diff) { + return "string"; + } + + return new \stdClass(); + } + + public function returnMultiButAlwaysMixed() -> mixed | var | int + { + // Maybe in future make sense to generate with `IS_MIXED`. + return "ZEND_BEGIN_ARG_INFO_EX"; + } +} diff --git a/tests/Extension/Types/MixedTest.php b/tests/Extension/Types/MixedTest.php new file mode 100644 index 0000000000..cf87d94b30 --- /dev/null +++ b/tests/Extension/Types/MixedTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Extension\Types; + +use PHPUnit\Framework\TestCase; +use Stub\Types\MixedType; + +final class MixedTest extends TestCase +{ + public function testReturnsOfMixedType(): void + { + $returns = new MixedType(); + + $this->assertEquals((new \stdClass()), $returns->returnMixedObject()); + $this->assertSame([], $returns->returnMixedArray()); + $this->assertSame('mixed string', $returns->returnMixedString()); + $this->assertSame(1, $returns->returnMixedInt()); + $this->assertSame(3.14, $returns->returnMixedFloat()); + $this->assertSame(true, $returns->returnMixedBool()); + $this->assertSame(null, $returns->returnMixedNull()); + + $this->assertNotNull($returns->returnMixedObject()); + $this->assertNotNull($returns->returnMixedArray()); + $this->assertNotNull($returns->returnMixedString()); + $this->assertNotNull($returns->returnMixedInt()); + $this->assertNotNull($returns->returnMixedFloat()); + $this->assertNotNull($returns->returnMixedBool()); + $this->assertNull($returns->returnMixedNull()); + + $this->assertEquals((new \stdClass()), $returns->returnMixed74()); + $this->assertSame('string', $returns->returnMixed74(true)); + $this->assertEquals((new \stdClass()), $returns->returnMixed74(false)); + } +}