Skip to content

Commit

Permalink
Merge branch '8.5' into 9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 24, 2022
2 parents 9c8cb53 + 7a77a52 commit 5be3707
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 98 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

98 changes: 88 additions & 10 deletions src/Framework/MockObject/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,58 @@
*/
final class Generator
{
private const MOCKED_CLONE_METHOD_WITH_VOID_RETURN_TYPE_TRAIT = <<<'EOT'
namespace PHPUnit\Framework\MockObject;
trait MockedCloneMethodWithVoidReturnType
{
public function __clone(): void
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler();
}
}
EOT;

private const MOCKED_CLONE_METHOD_WITHOUT_RETURN_TYPE_TRAIT = <<<'EOT'
namespace PHPUnit\Framework\MockObject;
trait MockedCloneMethodWithoutReturnType
{
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler();
}
}
EOT;

private const UNMOCKED_CLONE_METHOD_WITH_VOID_RETURN_TYPE_TRAIT = <<<'EOT'
namespace PHPUnit\Framework\MockObject;
trait UnmockedCloneMethodWithVoidReturnType
{
public function __clone(): void
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler();
parent::__clone();
}
}
EOT;

private const UNMOCKED_CLONE_METHOD_WITHOUT_RETURN_TYPE_TRAIT = <<<'EOT'
namespace PHPUnit\Framework\MockObject;
trait UnmockedCloneMethodWithoutReturnType
{
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler();
parent::__clone();
}
}
EOT;

/**
* @var array
*/
Expand Down Expand Up @@ -913,19 +965,11 @@ private function generateMock(string $type, ?array $explicitMethods, string $moc
$cloneTrait = '';

if ($mockedCloneMethod) {
if (PHP_MAJOR_VERSION >= 8) {
$cloneTrait = PHP_EOL . ' use \PHPUnit\Framework\MockObject\MockedCloneMethodWithVoidReturnType;';
} else {
$cloneTrait = PHP_EOL . ' use \PHPUnit\Framework\MockObject\MockedCloneMethodWithoutReturnType;';
}
$cloneTrait = $this->mockedCloneMethod();
}

if ($unmockedCloneMethod) {
if (PHP_MAJOR_VERSION >= 8) {
$cloneTrait = PHP_EOL . ' use \PHPUnit\Framework\MockObject\UnmockedCloneMethodWithVoidReturnType;';
} else {
$cloneTrait = PHP_EOL . ' use \PHPUnit\Framework\MockObject\UnmockedCloneMethodWithoutReturnType;';
}
$cloneTrait = $this->unmockedCloneMethod();
}

$classTemplate->setVar(
Expand Down Expand Up @@ -1070,4 +1114,38 @@ private function isConstructor(ReflectionMethod $method): bool

return $methodName === $className;
}

private function mockedCloneMethod(): string
{
if (PHP_MAJOR_VERSION >= 8) {
if (!trait_exists('\PHPUnit\Framework\MockObject\MockedCloneMethodWithVoidReturnType')) {
eval(self::MOCKED_CLONE_METHOD_WITH_VOID_RETURN_TYPE_TRAIT);
}

return PHP_EOL . ' use \PHPUnit\Framework\MockObject\MockedCloneMethodWithVoidReturnType;';
}

if (!trait_exists('\PHPUnit\Framework\MockObject\MockedCloneMethodWithoutReturnType')) {
eval(self::MOCKED_CLONE_METHOD_WITHOUT_RETURN_TYPE_TRAIT);
}

return PHP_EOL . ' use \PHPUnit\Framework\MockObject\MockedCloneMethodWithoutReturnType;';
}

private function unmockedCloneMethod(): string
{
if (PHP_MAJOR_VERSION >= 8) {
if (!trait_exists('\PHPUnit\Framework\MockObject\UnmockedCloneMethodWithVoidReturnType')) {
eval(self::UNMOCKED_CLONE_METHOD_WITH_VOID_RETURN_TYPE_TRAIT);
}

return PHP_EOL . ' use \PHPUnit\Framework\MockObject\UnmockedCloneMethodWithVoidReturnType;';
}

if (!trait_exists('\PHPUnit\Framework\MockObject\UnmockedCloneMethodWithoutReturnType')) {
eval(self::UNMOCKED_CLONE_METHOD_WITHOUT_RETURN_TYPE_TRAIT);
}

return PHP_EOL . ' use \PHPUnit\Framework\MockObject\UnmockedCloneMethodWithoutReturnType;';
}
}

0 comments on commit 5be3707

Please sign in to comment.