Skip to content

Commit

Permalink
Closes #5416
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 8, 2024
1 parent 8dee66b commit 39f4de2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 93 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.');
}
}
19 changes: 3 additions & 16 deletions src/Framework/MockObject/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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\GeneratedAsMockObject;
Expand Down Expand Up @@ -299,6 +296,7 @@ private function getObject(MockType $mockClass, bool $callOriginalConstructor =
* @throws ClassIsEnumerationException
* @throws ClassIsFinalException
* @throws ClassIsReadonlyException
* @throws MethodNamedMethodException
* @throws ReflectionException
* @throws RuntimeException
*/
Expand Down Expand Up @@ -466,21 +464,10 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject,
}

if ($mockMethods->hasMethod('method') || (isset($class) && $class->hasMethod('method'))) {
$message = 'Doubling interfaces (or classes) that have a method named "method" is deprecated. Support for this will be removed in PHPUnit 12.';

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 ($doubledCloneMethod) {
$traits[] = DoubledCloneMethod::class;
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 39f4de2

Please sign in to comment.