-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d62a25e
commit 658d8de
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/end-to-end/mock-objects/mock-method/with_argument_default_new_expression.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
https://github.com/sebastianbergmann/phpunit/issues/4929 | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
class Foo | ||
{ | ||
} | ||
|
||
class Bar | ||
{ | ||
public function method(Foo $foo = new Foo(1, 2, 3)) | ||
{ | ||
} | ||
} | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
$class = new ReflectionClass(Bar::class); | ||
|
||
$mockMethod = \PHPUnit\Framework\MockObject\MockMethod::fromReflection( | ||
$class->getMethod('method'), | ||
false, | ||
false | ||
); | ||
|
||
$code = $mockMethod->generateCode(); | ||
|
||
print $code; | ||
--EXPECT-- | ||
|
||
public function method(Foo $foo = new \Foo(1, 2, 3)) | ||
{ | ||
$__phpunit_arguments = [$foo]; | ||
$__phpunit_count = func_num_args(); | ||
|
||
if ($__phpunit_count > 1) { | ||
$__phpunit_arguments_tmp = func_get_args(); | ||
|
||
for ($__phpunit_i = 1; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { | ||
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; | ||
} | ||
} | ||
|
||
$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke( | ||
new \PHPUnit\Framework\MockObject\Invocation( | ||
'Bar', 'method', $__phpunit_arguments, '', $this, false | ||
) | ||
); | ||
|
||
return $__phpunit_result; | ||
} |