Skip to content

Commit

Permalink
Closes #5536
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 17, 2024
1 parent c90e9bd commit 67393b5
Show file tree
Hide file tree
Showing 72 changed files with 6 additions and 227 deletions.
19 changes: 3 additions & 16 deletions src/Framework/MockObject/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
use PHPUnit\Framework\MockObject\ConfigurableMethod;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
use PHPUnit\Framework\MockObject\ErrorCloneMethod;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\GeneratedAsTestStub;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\MockObjectApi;
Expand Down Expand Up @@ -92,7 +90,7 @@ final class Generator
* @throws RuntimeException
* @throws UnknownTypeException
*/
public function testDouble(string $type, bool $mockObject, bool $markAsMockObject, ?array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $returnValueGeneration = true): MockObject|Stub
public function testDouble(string $type, bool $mockObject, ?array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $returnValueGeneration = true): MockObject|Stub
{
if ($type === Traversable::class) {
$type = Iterator::class;
Expand All @@ -105,7 +103,6 @@ public function testDouble(string $type, bool $mockObject, bool $markAsMockObjec
$mock = $this->generate(
$type,
$mockObject,
$markAsMockObject,
$methods,
$mockClassName,
$callOriginalClone,
Expand Down Expand Up @@ -190,7 +187,6 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock
return $this->testDouble(
$intersectionName,
$mockObject,
$mockObject,
returnValueGeneration: $returnValueGeneration,
);
}
Expand All @@ -205,13 +201,12 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock
*
* @see https://github.com/sebastianbergmann/phpunit/issues/5476
*/
public function generate(string $type, bool $mockObject, bool $markAsMockObject, ?array $methods = null, string $mockClassName = '', bool $callOriginalClone = true): MockClass
public function generate(string $type, bool $mockObject, ?array $methods = null, string $mockClassName = '', bool $callOriginalClone = true): MockClass
{
if ($mockClassName !== '') {
return $this->generateCodeForTestDoubleClass(
$type,
$mockObject,
$markAsMockObject,
$methods,
$mockClassName,
$callOriginalClone,
Expand All @@ -221,7 +216,6 @@ public function generate(string $type, bool $mockObject, bool $markAsMockObject,
$key = md5(
$type .
($mockObject ? 'MockObject' : 'TestStub') .
($markAsMockObject ? 'MockObject' : 'TestStub') .
serialize($methods) .
serialize($callOriginalClone),
);
Expand All @@ -230,7 +224,6 @@ public function generate(string $type, bool $mockObject, bool $markAsMockObject,
self::$cache[$key] = $this->generateCodeForTestDoubleClass(
$type,
$mockObject,
$markAsMockObject,
$methods,
$mockClassName,
$callOriginalClone,
Expand Down Expand Up @@ -313,7 +306,7 @@ private function getObject(MockType $mockClass, bool $callOriginalConstructor =
* @throws ReflectionException
* @throws RuntimeException
*/
private function generateCodeForTestDoubleClass(string $type, bool $mockObject, bool $markAsMockObject, ?array $explicitMethods, string $mockClassName, bool $callOriginalClone): MockClass
private function generateCodeForTestDoubleClass(string $type, bool $mockObject, ?array $explicitMethods, string $mockClassName, bool $callOriginalClone): MockClass
{
$classTemplate = $this->loadTemplate('test_double_class.tpl');
$additionalInterfaces = [];
Expand Down Expand Up @@ -480,12 +473,6 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject,
$traits[] = MockObjectApi::class;
}

if ($markAsMockObject) {
$traits[] = GeneratedAsMockObject::class;
} else {
$traits[] = GeneratedAsTestStub::class;
}

if ($mockMethods->hasMethod('method') || (isset($class) && $class->hasMethod('method'))) {
throw new MethodNamedMethodException;
}
Expand Down
1 change: 0 additions & 1 deletion src/Framework/MockObject/MockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function getMock(): MockObject
$object = $this->generator->testDouble(
$this->type,
true,
true,
!$this->emptyMethodsArray ? $this->methods : null,
$this->constructorArgs,
$this->mockClassName ?? '',
Expand Down
21 changes: 0 additions & 21 deletions src/Framework/MockObject/Runtime/Api/GeneratedAsMockObject.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Framework/MockObject/Runtime/Api/GeneratedAsTestStub.php

This file was deleted.

27 changes: 0 additions & 27 deletions src/Framework/MockObject/Runtime/Api/MockObjectApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
*/
namespace PHPUnit\Framework\MockObject;

use function assert;
use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException;
use PHPUnit\Event\Code\TestMethodBuilder;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker as InvocationMockerBuilder;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;

Expand Down Expand Up @@ -45,29 +41,6 @@ abstract public function __phpunit_unsetInvocationMocker(): void;

public function expects(InvocationOrder $matcher): InvocationMockerBuilder
{
assert($this instanceof StubInternal);

if (!$this->__phpunit_wasGeneratedAsMockObject()) {
$message = 'Expectations configured on test doubles that are created as test stubs are no longer verified since PHPUnit 10. Test doubles that are created as test stubs will no longer have the expects() method in PHPUnit 12. Update your test code to use createMock() instead of createStub(), for example.';

try {
$test = TestMethodBuilder::fromCallStack();

if (!$this->__phpunit_state()->wasDeprecationAlreadyEmittedFor($test->id())) {
EventFacade::emitter()->testTriggeredPhpunitDeprecation(
$test,
$message,
);

$this->__phpunit_state()->deprecationWasEmittedFor($test->id());
}
// @codeCoverageIgnoreStart
} catch (NoTestCaseObjectOnCallStackException) {
EventFacade::emitter()->testRunnerTriggeredDeprecation($message);
// @codeCoverageIgnoreEnd
}
}

return $this->__phpunit_getInvocationHandler()->expects($matcher);
}
}
2 changes: 0 additions & 2 deletions src/Framework/MockObject/Runtime/Interface/StubInternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ public function __phpunit_state(): TestDoubleState;
public function __phpunit_getInvocationHandler(): InvocationHandler;

public function __phpunit_unsetInvocationMocker(): void;

public function __phpunit_wasGeneratedAsMockObject(): bool;
}
2 changes: 1 addition & 1 deletion src/Framework/MockObject/Runtime/ReturnValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private function newInstanceOf(string $stubClassName, string $className, string
private function testDoubleFor(string $type, string $className, string $methodName): Stub
{
try {
return (new Generator)->testDouble($type, false, false, [], [], '', false);
return (new Generator)->testDouble($type, false, [], [], '', false);
} catch (Throwable $t) {
throw new RuntimeException(
sprintf(
Expand Down
2 changes: 0 additions & 2 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ final protected function createMock(string $originalClassName): MockObject
$mock = (new MockGenerator)->testDouble(
$originalClassName,
true,
true,
callOriginalConstructor: false,
callOriginalClone: false,
returnValueGeneration: self::generateReturnValuesForTestDoubles(),
Expand Down Expand Up @@ -2172,7 +2171,6 @@ final protected static function createStub(string $originalClassName): Stub
{
$stub = (new MockGenerator)->testDouble(
$originalClassName,
true,
false,
callOriginalConstructor: false,
callOriginalClone: false,
Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/mock-objects/generator/232.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true,
Expand All @@ -60,7 +59,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
Issue3154::class,
true,
true,
[],
'Issue3154Mock',
true,
Expand All @@ -45,7 +44,6 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/mock-objects/generator/3967.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Baz',
true,
true,
[],
'MockBaz',
true,
Expand All @@ -33,7 +32,6 @@ class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\Moc
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\ProxiedCloneMethod;

Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/mock-objects/generator/397.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
C::class,
true,
true,
[],
'MockC',
true,
Expand All @@ -31,7 +30,6 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObjectInternal
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
3 changes: 1 addition & 2 deletions tests/end-to-end/mock-objects/generator/4139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require_once __DIR__ . '/../../../bootstrap.php';

$generator = new \PHPUnit\Framework\MockObject\Generator\Generator;

$mock = $generator->generate(InterfaceWithConstructor::class, true, true);
$mock = $generator->generate(InterfaceWithConstructor::class, true);

print $mock->classCode();
--EXPECTF--
Expand All @@ -20,7 +20,6 @@ class %s implements PHPUnit\Framework\MockObject\MockObjectInternal, InterfaceWi
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/mock-objects/generator/abstract_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true,
Expand All @@ -35,7 +34,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/mock-objects/generator/class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true,
Expand All @@ -35,7 +34,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true
Expand All @@ -30,7 +29,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\ProxiedCloneMethod;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true
Expand All @@ -30,7 +29,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
false
Expand All @@ -30,7 +29,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $generator = new \PHPUnit\Framework\MockObject\Generator\Generator;
$mock = $generator->generate(
'Foo',
true,
true,
[],
'MockFoo',
true
Expand All @@ -30,7 +29,6 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInte
{
use PHPUnit\Framework\MockObject\%SStubApi;
use PHPUnit\Framework\MockObject\MockObjectApi;
use PHPUnit\Framework\MockObject\GeneratedAsMockObject;
use PHPUnit\Framework\MockObject\Method;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
}
Loading

0 comments on commit 67393b5

Please sign in to comment.