Skip to content

Commit

Permalink
Local variables in generated test double code must be prefixed with _…
Browse files Browse the repository at this point in the history
…_phpunit_
  • Loading branch information
sebastianbergmann committed Jan 12, 2024
1 parent 547b9dd commit 8ba92b6
Show file tree
Hide file tree
Showing 79 changed files with 957 additions and 783 deletions.
20 changes: 11 additions & 9 deletions src/Framework/MockObject/Generator/templates/doubled_method.tpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

{modifier} function {reference}{method_name}({arguments_decl}){return_declaration}
{{deprecation}
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [{arguments_call}];
$__phpunit_count = func_num_args();

Expand All @@ -23,7 +24,8 @@
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
20 changes: 11 additions & 9 deletions src/Framework/MockObject/Generator/templates/proxied_method.tpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

{modifier} function {reference}{method_name}({arguments_decl}){return_declaration}
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];
foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [{arguments_call}];
$__phpunit_count = func_num_args();

Expand All @@ -23,7 +24,8 @@
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
20 changes: 11 additions & 9 deletions tests/end-to-end/mock-objects/generator/232.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte

public function speak()
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -86,7 +87,8 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework

public function a(int $i = %d, int $j = 17, string $v = '%s', string $z = '#'): string
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [$i, $j, $v, $z];
$__phpunit_count = func_num_args();

Expand All @@ -71,7 +72,8 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
20 changes: 11 additions & 9 deletions tests/end-to-end/mock-objects/generator/3967.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\Moc

public function foo(): string
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -59,7 +60,8 @@ class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\Moc
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
20 changes: 11 additions & 9 deletions tests/end-to-end/mock-objects/generator/397.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObjectInternal

public function m(?C $other): C
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [$other];
$__phpunit_count = func_num_args();

Expand All @@ -57,7 +58,8 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObjectInternal
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
20 changes: 11 additions & 9 deletions tests/end-to-end/mock-objects/generator/4139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ class %s implements PHPUnit\Framework\MockObject\MockObjectInternal, InterfaceWi

public function __construct()
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -47,7 +48,8 @@ class %s implements PHPUnit\Framework\MockObject\MockObjectInternal, InterfaceWi
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
60 changes: 33 additions & 27 deletions tests/end-to-end/mock-objects/generator/abstract_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte

public function one()
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -61,7 +62,8 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand All @@ -74,18 +76,19 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte

public function two()
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -96,7 +99,8 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand All @@ -109,18 +113,19 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte

protected function three()
{
$definedVariables = get_defined_vars();
$namedVariadicParameters = [];
foreach ($definedVariables as $name => $value) {
$reflectionParam = new ReflectionParameter([__CLASS__, __FUNCTION__], $name);
if ($reflectionParam->isVariadic()) {
foreach ($value as $key => $namedValue) {
if (is_string($key)) {
$namedVariadicParameters[$key] = $namedValue;
$__phpunit_definedVariables = get_defined_vars();
$__phpunit_namedVariadicParameters = [];

foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) {
if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) {
foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) {
if (is_string($__phpunit_key)) {
$__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue;
}
}
}
}

$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

Expand All @@ -131,7 +136,8 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}
$__phpunit_arguments = array_merge($__phpunit_arguments, $namedVariadicParameters);

$__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters);

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
Expand Down
Loading

0 comments on commit 8ba92b6

Please sign in to comment.