Skip to content

Commit

Permalink
Closes #5536
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 25, 2024
1 parent 1b86175 commit 44749d9
Show file tree
Hide file tree
Showing 72 changed files with 6 additions and 224 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 IteratorAggregate;
use PHPUnit\Framework\MockObject\ConfigurableMethod;
use PHPUnit\Framework\MockObject\DoubledCloneMethod;
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 @@ -90,7 +88,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 @@ -103,7 +101,6 @@ public function testDouble(string $type, bool $mockObject, bool $markAsMockObjec
$mock = $this->generate(
$type,
$mockObject,
$markAsMockObject,
$methods,
$mockClassName,
$callOriginalClone,
Expand Down Expand Up @@ -188,7 +185,6 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock
return $this->testDouble(
$intersectionName,
$mockObject,
$mockObject,
returnValueGeneration: $returnValueGeneration,
);
}
Expand All @@ -204,13 +200,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 @@ -220,7 +215,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 @@ -229,7 +223,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 @@ -305,7 +298,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 @@ -462,12 +455,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 @@ -86,7 +86,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.

25 changes: 0 additions & 25 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,27 +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 (!isset(self::$__phpunit_deprecation_emitted_for_test[$test->id()])) {
EventFacade::emitter()->testTriggeredPhpunitDeprecation(
$test,
$message,
);

self::$__phpunit_deprecation_emitted_for_test[$test->id()] = true;
}
} catch (NoTestCaseObjectOnCallStackException) {
EventFacade::emitter()->testRunnerTriggeredDeprecation($message);
}
}

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 @@ -21,6 +21,4 @@ public function __phpunit_getInvocationHandler(): InvocationHandler;
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void;

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 @@ -1189,7 +1189,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 @@ -2181,7 +2180,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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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\StubApi;
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 44749d9

Please sign in to comment.