diff --git a/src/Framework/MockObject/MockMethod.php b/src/Framework/MockObject/MockMethod.php index 6b5efd1bedc..ccefba8bca3 100644 --- a/src/Framework/MockObject/MockMethod.php +++ b/src/Framework/MockObject/MockMethod.php @@ -306,7 +306,7 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for if (!$parameter->isVariadic()) { if ($parameter->isDefaultValueAvailable()) { try { - $value = $parameter->getDefaultValueConstantName(); + $value = \var_export($parameter->getDefaultValue(), true); } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), @@ -314,22 +314,6 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for $e ); } - - if ($value === null) { - try { - $value = \var_export($parameter->getDefaultValue(), true); - } catch (\ReflectionException $e) { - throw new RuntimeException( - $e->getMessage(), - (int) $e->getCode(), - $e - ); - } - } elseif (!\defined($value)) { - $rootValue = \preg_replace('/^.*\\\\/', '', $value); - $value = \defined($rootValue) ? $rootValue : $value; - } - $default = ' = ' . $value; } elseif ($parameter->isOptional()) { $default = ' = null'; diff --git a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt index 45f83324fd8..a50677a6438 100644 --- a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt +++ b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt @@ -14,7 +14,7 @@ namespace Is\Namespaced; */ const A_CONSTANT = 17; -const PHP_VERSION = "0.0.0"; +const PHP_VERSION = ""; class Issue3154 { @@ -45,7 +45,7 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework use \PHPUnit\Framework\MockObject\Method; use \PHPUnit\Framework\MockObject\MockedCloneMethod; - public function a(int $i = PHP_INT_MAX, int $j = Is\Namespaced\A_CONSTANT, string $v = PHP_VERSION, string $z = '#'): string + public function a(int $i = %d, int $j = 17, string $v = '%s', string $z = '#'): string { $__phpunit_arguments = [$i, $j, $v, $z]; $__phpunit_count = func_num_args(); diff --git a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt index 09d3aea05f6..c620a20cff7 100644 --- a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt +++ b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt @@ -4,7 +4,7 @@ generateCode(); print $code; --EXPECT-- -private function bar($arg = FOO_CONST) +private function bar($a = 1, $b = 2, $c = 3, $d = 4) { - $__phpunit_arguments = [$arg]; + $__phpunit_arguments = [$a, $b, $c, $d]; $__phpunit_count = func_num_args(); - if ($__phpunit_count > 1) { + if ($__phpunit_count > 4) { $__phpunit_arguments_tmp = func_get_args(); - for ($__phpunit_i = 1; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { + for ($__phpunit_i = 4; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; } }