|
| 1 | +--TEST-- |
| 2 | +https://github.com/sebastianbergmann/phpunit-mock-objects/issues/420 |
| 3 | +https://github.com/sebastianbergmann/phpunit/issues/3154 |
| 4 | +--FILE-- |
| 5 | +<?php |
| 6 | +namespace Is\Namespaced; |
| 7 | +/* |
| 8 | + * This file is part of PHPUnit. |
| 9 | + * |
| 10 | + * (c) Sebastian Bergmann <sebastian@phpunit.de> |
| 11 | + * |
| 12 | + * For the full copyright and license information, please view the LICENSE |
| 13 | + * file that was distributed with this source code. |
| 14 | + */ |
| 15 | + |
| 16 | +const A_CONSTANT = 17; |
| 17 | +const PHP_VERSION = "0.0.0"; |
| 18 | + |
| 19 | +class Issue3154 |
| 20 | +{ |
| 21 | + public function a(int $i = PHP_INT_MAX, int $j = A_CONSTANT, string $v = \PHP_VERSION, string $z = '#'): string |
| 22 | + { |
| 23 | + return $z."sum: ".($i+$j).$v; |
| 24 | + } |
| 25 | +} |
| 26 | +require __DIR__ . '/../../../../vendor/autoload.php'; |
| 27 | + |
| 28 | +$generator = new \PHPUnit\Framework\MockObject\Generator; |
| 29 | + |
| 30 | +$mock = $generator->generate( |
| 31 | + Issue3154::class, |
| 32 | + [], |
| 33 | + 'Issue3154Mock', |
| 34 | + true, |
| 35 | + true |
| 36 | +); |
| 37 | + |
| 38 | +print $mock['code']; |
| 39 | +--EXPECT-- |
| 40 | +class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework\MockObject\MockObject |
| 41 | +{ |
| 42 | + private $__phpunit_invocationMocker; |
| 43 | + private $__phpunit_originalObject; |
| 44 | + private $__phpunit_configurable = ['a']; |
| 45 | + private $__phpunit_returnValueGeneration = true; |
| 46 | + |
| 47 | + public function __clone() |
| 48 | + { |
| 49 | + $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); |
| 50 | + } |
| 51 | + |
| 52 | + public function a(int $i = PHP_INT_MAX, int $j = Is\Namespaced\A_CONSTANT, string $v = PHP_VERSION, string $z = '#'): string |
| 53 | + { |
| 54 | + $__phpunit_arguments = [$i, $j, $v, $z]; |
| 55 | + $__phpunit_count = func_num_args(); |
| 56 | + |
| 57 | + if ($__phpunit_count > 4) { |
| 58 | + $__phpunit_arguments_tmp = func_get_args(); |
| 59 | + |
| 60 | + for ($__phpunit_i = 4; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { |
| 61 | + $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( |
| 66 | + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( |
| 67 | + 'Is\Namespaced\Issue3154', 'a', $__phpunit_arguments, 'string', $this, true |
| 68 | + ) |
| 69 | + ); |
| 70 | + |
| 71 | + return $__phpunit_result; |
| 72 | + } |
| 73 | + |
| 74 | + public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher) |
| 75 | + { |
| 76 | + return $this->__phpunit_getInvocationMocker()->expects($matcher); |
| 77 | + } |
| 78 | + |
| 79 | + public function method() |
| 80 | + { |
| 81 | + $any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount; |
| 82 | + $expects = $this->expects($any); |
| 83 | + |
| 84 | + return call_user_func_array([$expects, 'method'], func_get_args()); |
| 85 | + } |
| 86 | + |
| 87 | + public function __phpunit_setOriginalObject($originalObject) |
| 88 | + { |
| 89 | + $this->__phpunit_originalObject = $originalObject; |
| 90 | + } |
| 91 | + |
| 92 | + public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration) |
| 93 | + { |
| 94 | + $this->__phpunit_returnValueGeneration = $returnValueGeneration; |
| 95 | + } |
| 96 | + |
| 97 | + public function __phpunit_getInvocationMocker() |
| 98 | + { |
| 99 | + if ($this->__phpunit_invocationMocker === null) { |
| 100 | + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); |
| 101 | + } |
| 102 | + |
| 103 | + return $this->__phpunit_invocationMocker; |
| 104 | + } |
| 105 | + |
| 106 | + public function __phpunit_hasMatchers() |
| 107 | + { |
| 108 | + return $this->__phpunit_getInvocationMocker()->hasMatchers(); |
| 109 | + } |
| 110 | + |
| 111 | + public function __phpunit_verify($unsetInvocationMocker = true) |
| 112 | + { |
| 113 | + $this->__phpunit_getInvocationMocker()->verify(); |
| 114 | + |
| 115 | + if ($unsetInvocationMocker) { |
| 116 | + $this->__phpunit_invocationMocker = null; |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments