Skip to content

Commit

Permalink
fix(StubClassFactory) support PHPUnit >= 10
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Jul 17, 2024
1 parent 13f393e commit e9056ec
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/_support/StubClassFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Codeception\Stub;
use Exception;
use lucatume\WPBrowser\Utils\Property;
use PHPUnit\Event\Runtime\PHPUnit;
use PHPUnit\Runner\Version;
use ReflectionException;
use ReflectionMethod;

Expand Down Expand Up @@ -35,11 +37,25 @@ public static function connectInvocationMocker(object $mock): void
$mockClassName = get_class($mock);
[$class, $parameters] = self::$stubParametersByClassName[$mockClassName];
$stub = Stub::makeEmpty($class, $parameters);
Property::setPrivateProperties($mock, [
'__phpunit_originalObject' => Property::readPrivate($stub, '__phpunit_originalObject'),
'__phpunit_returnValueGeneration' => Property::readPrivate($stub, '__phpunit_returnValueGeneration'),
'__phpunit_invocationMocker' => Property::readPrivate($stub, '__phpunit_invocationMocker'),
]);
$phpuniStateProperty = null;

try {
$phpuniStateProperty = Property::readPrivate($stub, '__phpunit_state');
} catch (\Throwable $t) {
// PHPUnit < 10.0.0.
}

if ($phpuniStateProperty) {
// PHPUnit >= 10.0.0.
Property::setPrivateProperties($mock, ['__phpunit_state' => $phpuniStateProperty]);
} else {
Property::setPrivateProperties($mock, [
'__phpunit_originalObject' => Property::readPrivate($stub, '__phpunit_originalObject'),
'__phpunit_returnValueGeneration' => Property::readPrivate($stub, '__phpunit_returnValueGeneration'),
'__phpunit_invocationMocker' => Property::readPrivate($stub, '__phpunit_invocationMocker'),
]);
}

unset($stub);
}

Expand Down

0 comments on commit e9056ec

Please sign in to comment.