Skip to content

Commit

Permalink
Closes #5416
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 5, 2024
1 parent 90bbf2c commit 983b255
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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\Generator;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class MethodNamedMethodException extends \PHPUnit\Framework\Exception implements Exception
{
public function __construct()
{
parent::__construct('Doubling interfaces (or classes) that have a method named "method" is not supported.');
}
}
24 changes: 3 additions & 21 deletions src/Framework/MockObject/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
use Exception;
use Iterator;
use IteratorAggregate;
use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException;
use PHPUnit\Event\Code\TestMethodBuilder;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Framework\MockObject\ConfigurableMethod;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
use PHPUnit\Framework\MockObject\ErrorCloneMethod;
Expand Down Expand Up @@ -312,6 +309,7 @@ private function getObject(MockType $mockClass, bool $callOriginalConstructor =
/**
* @throws ClassIsEnumerationException
* @throws ClassIsFinalException
* @throws MethodNamedMethodException
* @throws ReflectionException
* @throws RuntimeException
*/
Expand Down Expand Up @@ -489,26 +487,10 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject,
}

if ($mockMethods->hasMethod('method') || (isset($class) && $class->hasMethod('method'))) {
$message = sprintf(
'%s %s has a method named "method". Doubling %s that have a method named "method" is deprecated. Support for this will be removed in PHPUnit 12.',
($isInterface) ? 'Interface' : 'Class',
isset($class) ? $class->getName() : $type,
($isInterface) ? 'interfaces' : 'classes',
);

try {
EventFacade::emitter()->testTriggeredPhpunitDeprecation(
TestMethodBuilder::fromCallStack(),
$message,
);
} catch (NoTestCaseObjectOnCallStackException) {
EventFacade::emitter()->testRunnerTriggeredDeprecation($message);
}
throw new MethodNamedMethodException;
}

if (!$mockMethods->hasMethod('method') && (!isset($class) || !$class->hasMethod('method'))) {
$traits[] = Method::class;
}
$traits[] = Method::class;

if ($isPhp82 && $isReadonly) {
// @codeCoverageIgnoreStart
Expand Down
2 changes: 0 additions & 2 deletions src/Framework/MockObject/Runtime/Interface/MockObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;

/**
* @method InvocationMocker method($constraint)
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
interface MockObject extends Stub
Expand Down
3 changes: 1 addition & 2 deletions src/Framework/MockObject/Runtime/Interface/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
use PHPUnit\Framework\MockObject\Builder\InvocationStubber;

/**
* @method InvocationStubber method($constraint)
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
interface Stub
{
public function method(): InvocationStubber;
}

This file was deleted.

0 comments on commit 983b255

Please sign in to comment.