diff options
| author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-04-06 11:02:13 +0200 |
|---|---|---|
| committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-04-08 18:37:51 +0200 |
| commit | 3709e74b5e495e210ada8039ed81fafa9cbadcdb (patch) | |
| tree | b7347572b1e22a2a27a45260b4f4773bf916b158 /ext/reflection/tests | |
| parent | b0d8f012f95ba1f2d8dba238c93baf3afb73b78e (diff) | |
| download | php-git-3709e74b5e495e210ada8039ed81fafa9cbadcdb.tar.gz | |
Store default parameter values of internal functions in arg info
Closes GH-5353. From now on, PHP will have reflection information
about default values of parameters of internal functions.
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Diffstat (limited to 'ext/reflection/tests')
11 files changed, 197 insertions, 19 deletions
diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index 2dc742e3ec..367645d019 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -131,7 +131,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String Method [ <internal:Reflection> public method getMethods ] { - Parameters [1] { - Parameter #0 [ <optional> ?int $filter ] + Parameter #0 [ <optional> ?int $filter = null ] } } @@ -152,7 +152,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String Method [ <internal:Reflection> public method getProperties ] { - Parameters [1] { - Parameter #0 [ <optional> ?int $filter ] + Parameter #0 [ <optional> ?int $filter = null ] } } @@ -259,7 +259,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String Method [ <internal:Reflection> public method newInstance ] { - Parameters [1] { - Parameter #0 [ <optional> ...$args ] + Parameter #0 [ <optional> ...$args = <default> ] } } @@ -272,7 +272,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String Method [ <internal:Reflection> public method newInstanceArgs ] { - Parameters [1] { - Parameter #0 [ <optional> array $args ] + Parameter #0 [ <optional> array $args = [] ] } } @@ -299,7 +299,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String - Parameters [2] { Parameter #0 [ <required> string $name ] - Parameter #1 [ <optional> $default ] + Parameter #1 [ <optional> $default = <default> ] } } diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt index 4f3f114bad..98fcf5afac 100644 --- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt +++ b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt @@ -11,13 +11,13 @@ function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1, $test3 = $reflect = new ReflectionFunction('ReflectionParameterTest'); foreach($reflect->getParameters() as $param) { if($param->getName() == 'test1') { - var_dump($param->isDefaultValueConstant()); + var_dump(@$param->isDefaultValueConstant()); } if($param->getName() == 'test2') { - var_dump($param->isDefaultValueConstant()); + var_dump(@$param->isDefaultValueConstant()); } - if($param->isDefaultValueAvailable() && $param->isDefaultValueConstant()) { - var_dump($param->getDefaultValueConstantName()); + if($param->isDefaultValueAvailable() && @$param->isDefaultValueConstant()) { + var_dump(@$param->getDefaultValueConstantName()); } } @@ -36,8 +36,8 @@ $method = new ReflectionMethod('Foo', 'baz'); $params = $method->getParameters(); foreach ($params as $param) { - if ($param->isDefaultValueConstant()) { - var_dump($param->getDefaultValueConstantName()); + if (@$param->isDefaultValueConstant()) { + var_dump(@$param->getDefaultValueConstantName()); } } ?> diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt index 28aeceeb2f..e3d3b9dd96 100644 --- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt +++ b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt @@ -17,14 +17,12 @@ namespace { } $reflect = new ReflectionFunction('ReflectionParameterTest'); foreach($reflect->getParameters() as $param) { - if($param->isDefaultValueAvailable() && $param->isDefaultValueConstant()) { - echo $param->getDefaultValueConstantName() . "\n"; + if($param->isDefaultValueAvailable() && @$param->isDefaultValueConstant()) { + echo @$param->getDefaultValueConstantName() . "\n"; } } - echo "==DONE=="; } ?> --EXPECT-- ReflectionTestNamespace\TestClass::TEST_CONST_2 ReflectionTestNamespace\CONST_TEST_1 -==DONE== diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt index 7f1451bbdb..9555152404 100644 --- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt +++ b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt @@ -12,8 +12,7 @@ $reflect = new ReflectionFunction('ReflectionParameterTest'); foreach($reflect->getParameters() as $param) { try { echo $param->getDefaultValueConstantName() . "\n"; - } - catch(ReflectionException $e) { + } catch(ReflectionException $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/reflection/tests/ReflectionParameter_export_basic.phpt b/ext/reflection/tests/ReflectionParameter_export_basic.phpt index 22b25de663..68a43610ef 100644 --- a/ext/reflection/tests/ReflectionParameter_export_basic.phpt +++ b/ext/reflection/tests/ReflectionParameter_export_basic.phpt @@ -12,6 +12,6 @@ foreach($reflect->getParameters() as $key => $value) { echo new ReflectionParameter('ReflectionParameterTest', $key), "\n"; } ?> ---EXPECTF-- +--EXPECT-- Parameter #0 [ <required> $test ] Parameter #1 [ <optional> $test2 = NULL ] diff --git a/ext/reflection/tests/ReflectionParameter_getDeclaringFunction_basic.phpt b/ext/reflection/tests/ReflectionParameter_getDeclaringFunction_basic.phpt index 7cbef67292..dee0196880 100644 --- a/ext/reflection/tests/ReflectionParameter_getDeclaringFunction_basic.phpt +++ b/ext/reflection/tests/ReflectionParameter_getDeclaringFunction_basic.phpt @@ -32,4 +32,3 @@ Function [ <user> function ReflectionParameterTest ] { Parameter #1 [ <optional> $test2 = NULL ] } } - diff --git a/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValueConstantName_Internal.phpt b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValueConstantName_Internal.phpt new file mode 100644 index 0000000000..b013c9db66 --- /dev/null +++ b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValueConstantName_Internal.phpt @@ -0,0 +1,53 @@ +--TEST-- +ReflectionParameter::getDefaultValueConstantName() should also work for parameters of internal functions. +--FILE-- +<?php +$class = new ReflectionClass('DateTime'); +$method = $class->getMethod('setTime'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->getDefaultValueConstantName()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('getTransitions'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->getDefaultValueConstantName()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('listIdentifiers'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->getDefaultValueConstantName()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +?> +--EXPECT-- +Internal error: Failed to retrieve the default value +Internal error: Failed to retrieve the default value +NULL +NULL +---------- +string(11) "PHP_INT_MIN" +string(11) "PHP_INT_MAX" +---------- +string(17) "DateTimeZone::ALL" +NULL diff --git a/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValue_Internal.phpt b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValue_Internal.phpt new file mode 100644 index 0000000000..c1e1a14b27 --- /dev/null +++ b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_getDefaultValue_Internal.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionParameter::getDefaultValue() should also work for parameters of internal functions. +--FILE-- +<?php +$class = new ReflectionClass('DateTime'); +$method = $class->getMethod('setTime'); + +foreach ($method->getParameters() as $k => $parameter) { + try { + var_dump($parameter->getDefaultValue()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('listIdentifiers'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->getDefaultValue()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +?> +--EXPECT-- +Internal error: Failed to retrieve the default value +Internal error: Failed to retrieve the default value +int(0) +int(0) +---------- +int(2047) +NULL diff --git a/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueAvailable_Internal.phpt b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueAvailable_Internal.phpt new file mode 100644 index 0000000000..bcdcb68f19 --- /dev/null +++ b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueAvailable_Internal.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionParameter::isDefaultValueAvailable() should also work for parameters of internal functions +--FILE-- +<?php +$class = new ReflectionClass('DateTime'); +$method = $class->getMethod('setTime'); + +foreach ($method->getParameters() as $parameter) { + var_dump($parameter->isDefaultValueAvailable()); +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('listIdentifiers'); + +foreach ($method->getParameters() as $parameter) { + var_dump($parameter->isDefaultValueAvailable()); +} +?> +--EXPECT-- +bool(false) +bool(false) +bool(true) +bool(true) +---------- +bool(true) +bool(true) diff --git a/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueConstant_Internal.phpt b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueConstant_Internal.phpt new file mode 100644 index 0000000000..35c5548074 --- /dev/null +++ b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_isDefaultValueConstant_Internal.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionParameter::isDefaultValueConstant() should also work for parameters of internal functions +--FILE-- +<?php +$class = new ReflectionClass('DateTime'); +$method = $class->getMethod('setTime'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->isDefaultValueConstant()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('listIdentifiers'); + +foreach ($method->getParameters() as $parameter) { + try { + var_dump($parameter->isDefaultValueConstant()); + } catch (ReflectionException $exception) { + echo $exception->getMessage() . "\n"; + } +} +?> +--EXPECT-- +Internal error: Failed to retrieve the default value +Internal error: Failed to retrieve the default value +bool(false) +bool(false) +---------- +bool(true) +bool(false) diff --git a/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_toString_Internal.phpt b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_toString_Internal.phpt new file mode 100644 index 0000000000..6697232869 --- /dev/null +++ b/ext/reflection/tests/internal_parameter_default_value/ReflectionParameter_toString_Internal.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionParameter::__toString() should display default values for internal functions as well +--FILE-- +<?php +$class = new ReflectionClass('DateTime'); +$method = $class->getMethod('setTime'); + +foreach ($method->getParameters() as $k => $parameter) { + echo $parameter . "\n"; +} + +echo "----------\n"; + +$class = new ReflectionClass('DateTimeZone'); +$method = $class->getMethod('listIdentifiers'); + +foreach ($method->getParameters() as $parameter) { + echo $parameter . "\n"; +} +?> +--EXPECT-- +Parameter #0 [ <required> int $hour ] +Parameter #1 [ <required> int $minute ] +Parameter #2 [ <optional> int $second = 0 ] +Parameter #3 [ <optional> int $microseconds = 0 ] +---------- +Parameter #0 [ <optional> int $what = DateTimeZone::ALL ] +Parameter #1 [ <optional> ?string $country = null ] |
