Skip to content

Commit

Permalink
Merge branch '7.5' into 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 2, 2019
2 parents 283c2f6 + 928b6e5 commit a6937bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
18 changes: 1 addition & 17 deletions src/Framework/MockObject/MockMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,30 +306,14 @@ 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(),
(int) $e->getCode(),
$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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Is\Namespaced;
*/

const A_CONSTANT = 17;
const PHP_VERSION = "0.0.0";
const PHP_VERSION = "";

class Issue3154
{
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<?php declare(strict_types=1);
class Foo
{
public function bar(int $baz = PHP_INT_MIN)
public function bar(int $baz = PHP_INT_MAX)
{
}
}
Expand All @@ -31,7 +31,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
use \PHPUnit\Framework\MockObject\Method;
use \PHPUnit\Framework\MockObject\MockedCloneMethod;

public function bar(int $baz = PHP_INT_MIN)
public function bar(int $baz = %d)
{
$__phpunit_arguments = [$baz];
$__phpunit_count = func_num_args();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
Mock static method
--FILE--
<?php declare(strict_types=1);
define('FOO_CONST', 1);
define('GLOBAL_CONSTANT', 1);

class Foo
{
private function bar($arg = FOO_CONST){}
public const CLASS_CONSTANT_PUBLIC = 2;
protected const CLASS_CONSTANT_PROTECTED = 3;
private const CLASS_CONSTANT_PRIVATE = 4;
private function bar($a = GLOBAL_CONSTANT, $b = self::CLASS_CONSTANT_PUBLIC, $c = self::CLASS_CONSTANT_PROTECTED, $d = self::CLASS_CONSTANT_PRIVATE){}
}

require __DIR__ . '/../../../../vendor/autoload.php';
Expand All @@ -23,15 +26,15 @@ $code = $mockMethod->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];
}
}
Expand Down

0 comments on commit a6937bf

Please sign in to comment.