Skip to content

Commit

Permalink
Merge pull request #42 from W0rma/fix-generator-phpunit-10-3
Browse files Browse the repository at this point in the history
Fix namespace for Generator in PHPUnit >= 10.3
  • Loading branch information
Naktibalda committed Aug 16, 2023
2 parents 58751ae + 6153a58 commit 4aaeffd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', '>=')
Expand Down
6 changes: 0 additions & 6 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4aaeffd

Please sign in to comment.