Skip to content

Commit

Permalink
Extract method() from template into trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 28, 2019
1 parent 6377eae commit 5496e01
Show file tree
Hide file tree
Showing 49 changed files with 76 additions and 371 deletions.
2 changes: 1 addition & 1 deletion src/Framework/MockObject/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ private function generateMock($type, ?array $explicitMethods, string $mockClassN
$method = '';

if (!$mockMethods->hasMethod('method') && (!isset($class) || !$class->hasMethod('method'))) {
$method = $this->getTemplate('mocked_class_method.tpl')->render();
$method = \PHP_EOL . ' use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;';
}

$classTemplate->setVar(
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/MockObject/Generator/mocked_class.tpl.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ declare(strict_types=1);

{prologue}{class_declaration}
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApi;{method}

{clone}{mocked_methods}{method}}{epilogue}
{clone}{mocked_methods}}{epilogue}

This file was deleted.

28 changes: 28 additions & 0 deletions src/Framework/MockObject/TestDoubleApiMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework\MockObject;

use PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;

/**
* @internal This trait is not covered by the backward compatibility promise for PHPUnit
*/
trait TestDoubleApiMethod
{
public function method()
{
$expects = $this->expects(new AnyInvokedCount);

return \call_user_func_array(
[$expects, 'method'],
\func_get_args()
);
}
}
9 changes: 1 addition & 8 deletions tests/end-to-end/mock-objects/generator/232.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -84,12 +85,4 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare(strict_types=1);
class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -69,12 +70,4 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
9 changes: 1 addition & 8 deletions tests/end-to-end/mock-objects/generator/397.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare(strict_types=1);
class MockC extends C implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -55,12 +56,4 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
9 changes: 1 addition & 8 deletions tests/end-to-end/mock-objects/generator/abstract_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -103,12 +104,4 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
9 changes: 1 addition & 8 deletions tests/end-to-end/mock-objects/generator/class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -81,12 +82,4 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,11 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
parent::__clone();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -55,12 +56,4 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
9 changes: 1 addition & 8 deletions tests/end-to-end/mock-objects/generator/class_partial.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare(strict_types=1);
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -59,12 +60,4 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare(strict_types=1);
class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -61,12 +62,4 @@ class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\Moc

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,10 @@ declare(strict_types=1);
class MockFoo extends ClassWithFinalMethod implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare(strict_types=1);
class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -55,12 +56,4 @@ class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments imp

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare(strict_types=1);
class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\TestDoubleApi;
use \PHPUnit\Framework\MockObject\TestDoubleApiMethod;

public function __clone()
{
Expand Down Expand Up @@ -55,12 +56,4 @@ class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements

return $__phpunit_result;
}

public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);

return call_user_func_array([$expects, 'method'], func_get_args());
}
}

0 comments on commit 5496e01

Please sign in to comment.