Skip to content

Commit 4aaeffd

Browse files
authored
Merge pull request #42 from W0rma/fix-generator-phpunit-10-3
Fix namespace for Generator in PHPUnit >= 10.3
2 parents 58751ae + 6153a58 commit 4aaeffd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Stub.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Codeception\Stub\StubMarshaler;
1010
use Exception;
1111
use LogicException;
12-
use PHPUnit\Framework\MockObject\Generator;
12+
use PHPUnit\Framework\MockObject\Generator as LegacyGenerator;
13+
use PHPUnit\Framework\MockObject\Generator\Generator;
1314
use PHPUnit\Framework\MockObject\MockObject as PHPUnitMockObject;
1415
use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount;
1516
use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls;
@@ -433,7 +434,12 @@ private static function doGenerateMock($args, $isAbstract = false)
433434
{
434435
$testCase = self::extractTestCaseFromArgs($args);
435436
$methodName = $isAbstract ? 'getMockForAbstractClass' : 'getMock';
436-
$generatorClass = new Generator;
437+
// PHPUnit 10.3 changed the namespace
438+
if (version_compare(PHPUnitVersion::series(), '10.3', '>=')) {
439+
$generatorClass = new Generator();
440+
} else {
441+
$generatorClass = new LegacyGenerator();
442+
}
437443

438444
// using PHPUnit 5.4 mocks registration
439445
if (version_compare(PHPUnitVersion::series(), '5.4', '>=')

tests/StubTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,6 @@ public function testStubMakeEmptyInterface()
387387
$stub = Stub::makeEmpty(Countable::class, ['count' => 5]);
388388
$this->assertEquals(5, $stub->count());
389389
}
390-
391-
private function assertObjectHasProperty(string $propertyName, object $object): void
392-
{
393-
$hasProperty = (new ReflectionObject($object))->hasProperty($propertyName);
394-
$this->assertTrue($hasProperty, sprintf("Object has no attribute %s", $propertyName));
395-
}
396390
}
397391

398392
class MyClassWithPrivateProperties

0 commit comments

Comments
 (0)