From 03b93cff29494cf240e67e6625cc32212bba9f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Mon, 9 Jul 2018 19:16:10 +0200 Subject: [PATCH 1/3] Generator will now try to fallback to root namespace constants --- src/Framework/MockObject/Generator.php | 3 + .../3154_namespaced_constant_resolving.phpt | 119 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/Framework/MockObject/Generator/3154_namespaced_constant_resolving.phpt diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php index c2d00a26733..1fa33a90f83 100644 --- a/src/Framework/MockObject/Generator.php +++ b/src/Framework/MockObject/Generator.php @@ -1167,6 +1167,9 @@ private function getMethodParameters(ReflectionMethod $method, $forCall = false) if ($value === null) { $value = \var_export($parameter->getDefaultValue(), true); + } elseif (!\defined($value)) { + $rootValue = \preg_replace('/^.*\\\\/', '', $value); + $value = \defined($rootValue) ? $rootValue : $value; } $default = ' = ' . $value; diff --git a/tests/Framework/MockObject/Generator/3154_namespaced_constant_resolving.phpt b/tests/Framework/MockObject/Generator/3154_namespaced_constant_resolving.phpt new file mode 100644 index 00000000000..8e434f50b73 --- /dev/null +++ b/tests/Framework/MockObject/Generator/3154_namespaced_constant_resolving.phpt @@ -0,0 +1,119 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit-mock-objects/issues/420 +https://github.com/sebastianbergmann/phpunit/issues/3154 +--FILE-- + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +const A_CONSTANT = 17; +const PHP_VERSION = "0.0.0"; + +class Issue3154 +{ + public function a(int $i = PHP_INT_MAX, int $j = A_CONSTANT, string $v = \PHP_VERSION, string $z = '#'): string + { + return $z."sum: ".($i+$j).$v; + } +} +require __DIR__ . '/../../../../vendor/autoload.php'; + +$generator = new \PHPUnit\Framework\MockObject\Generator; + +$mock = $generator->generate( + Issue3154::class, + [], + 'Issue3154Mock', + true, + true +); + +print $mock['code']; +--EXPECT-- +class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework\MockObject\MockObject +{ + private $__phpunit_invocationMocker; + private $__phpunit_originalObject; + private $__phpunit_configurable = ['a']; + private $__phpunit_returnValueGeneration = true; + + public function __clone() + { + $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); + } + + public function a(int $i = PHP_INT_MAX, int $j = Is\Namespaced\A_CONSTANT, string $v = PHP_VERSION, string $z = '#'): string + { + $__phpunit_arguments = [$i, $j, $v, $z]; + $__phpunit_count = func_num_args(); + + if ($__phpunit_count > 4) { + $__phpunit_arguments_tmp = func_get_args(); + + for ($__phpunit_i = 4; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { + $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; + } + } + + $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Is\Namespaced\Issue3154', 'a', $__phpunit_arguments, 'string', $this, true + ) + ); + + return $__phpunit_result; + } + + public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher) + { + return $this->__phpunit_getInvocationMocker()->expects($matcher); + } + + public function method() + { + $any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount; + $expects = $this->expects($any); + + return call_user_func_array([$expects, 'method'], func_get_args()); + } + + public function __phpunit_setOriginalObject($originalObject) + { + $this->__phpunit_originalObject = $originalObject; + } + + public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration) + { + $this->__phpunit_returnValueGeneration = $returnValueGeneration; + } + + public function __phpunit_getInvocationMocker() + { + if ($this->__phpunit_invocationMocker === null) { + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + } + + return $this->__phpunit_invocationMocker; + } + + public function __phpunit_hasMatchers() + { + return $this->__phpunit_getInvocationMocker()->hasMatchers(); + } + + public function __phpunit_verify($unsetInvocationMocker = true) + { + $this->__phpunit_getInvocationMocker()->verify(); + + if ($unsetInvocationMocker) { + $this->__phpunit_invocationMocker = null; + } + } +} From 2f2c03440a6558acdbf54a7c1025b6f86e6e6cf9 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 15 Jul 2018 07:18:28 +0200 Subject: [PATCH 2/3] Update ChangeLog --- ChangeLog-7.2.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog-7.2.md b/ChangeLog-7.2.md index b778c36d8a4..95b2510454c 100644 --- a/ChangeLog-7.2.md +++ b/ChangeLog-7.2.md @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 7.2 release series are documented in this fil ### Fixed +* Fixed [#3154](https://github.com/sebastianbergmann/phpunit/issues/3154): Global constants as default parameter values are not handled correctly in namespace * Fixed [#3189](https://github.com/sebastianbergmann/phpunit/issues/3189): PHPUnit 7.2 potentially leaves a messy libxmlerror state * Fixed [#3199](https://github.com/sebastianbergmann/phpunit/pull/3199): Code Coverage for PHPT tests does not work when PHPDBG is used From 8e878aff7917ef66e702e03d1359b16eee254e2c Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 15 Jul 2018 07:20:50 +0200 Subject: [PATCH 3/3] Prepare release --- ChangeLog-7.2.md | 2 +- src/Runner/Version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog-7.2.md b/ChangeLog-7.2.md index 95b2510454c..a99350d1ca1 100644 --- a/ChangeLog-7.2.md +++ b/ChangeLog-7.2.md @@ -2,7 +2,7 @@ All notable changes of the PHPUnit 7.2 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. -## [7.2.7] - 2018-MM-DD +## [7.2.7] - 2018-07-15 ### Fixed diff --git a/src/Runner/Version.php b/src/Runner/Version.php index 246d931016a..8f737419045 100644 --- a/src/Runner/Version.php +++ b/src/Runner/Version.php @@ -30,7 +30,7 @@ public static function id(): string } if (self::$version === null) { - $version = new VersionId('7.2.6', \dirname(__DIR__, 2)); + $version = new VersionId('7.2.7', \dirname(__DIR__, 2)); self::$version = $version->getVersion(); }