From 5b9253ca6fadc33d3b2d339d44e275e4bd8ee268 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 7 Aug 2023 06:20:40 +0200 Subject: [PATCH 1/2] Fix namespace for Generator in PHPUnit >= 10.3 --- src/Stub.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Stub.php b/src/Stub.php index ae31b40..d3a3fcc 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -9,7 +9,8 @@ use Codeception\Stub\StubMarshaler; use Exception; use LogicException; -use PHPUnit\Framework\MockObject\Generator; +use PHPUnit\Framework\MockObject\Generator as LegacyGenerator; +use PHPUnit\Framework\MockObject\Generator\Generator; use PHPUnit\Framework\MockObject\MockObject as PHPUnitMockObject; use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls; @@ -433,7 +434,12 @@ private static function doGenerateMock($args, $isAbstract = false) { $testCase = self::extractTestCaseFromArgs($args); $methodName = $isAbstract ? 'getMockForAbstractClass' : 'getMock'; - $generatorClass = new Generator; + // PHPUnit 10.3 changed the namespace + if (version_compare(PHPUnitVersion::series(), '10.3', '>=')) { + $generatorClass = new Generator(); + } else { + $generatorClass = new LegacyGenerator(); + } // using PHPUnit 5.4 mocks registration if (version_compare(PHPUnitVersion::series(), '5.4', '>=') From 6153a58ef6958ac6413ff8e46234f6a020ff4f30 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 7 Aug 2023 06:41:04 +0200 Subject: [PATCH 2/2] Remove unused method --- tests/StubTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/StubTest.php b/tests/StubTest.php index 9325ad4..e56c3b3 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -387,12 +387,6 @@ public function testStubMakeEmptyInterface() $stub = Stub::makeEmpty(Countable::class, ['count' => 5]); $this->assertEquals(5, $stub->count()); } - - private function assertObjectHasProperty(string $propertyName, object $object): void - { - $hasProperty = (new ReflectionObject($object))->hasProperty($propertyName); - $this->assertTrue($hasProperty, sprintf("Object has no attribute %s", $propertyName)); - } } class MyClassWithPrivateProperties