Skip to content

Commit

Permalink
Handle mocking readonly class (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrooo authored Jun 26, 2023
1 parent 110115e commit f53b07e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Utilities/DynamicProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ private static function getProxyClassDefinition(string $name, string $className)
} else {
$extendsClasses[] = $className;
}

$readonly = '';
if ($reflectionClass->isReadOnly()){
$readonly = 'readonly';
}
$extends = self::generateRelation('extends', $extendsClasses);
$implements = self::generateRelation('implements', $implementsInterfaces);
$code = "class {$name} {$extends} {$implements} {";
$code .= "public \$methodHandler;\n";

$code = "{$readonly} class {$name} {$extends} {$implements} {";
$code .= "public ?object \$methodHandler;\n";
$code .= "function __construct(\$methodHandler) { \$this->methodHandler = \$methodHandler; }\n";
foreach (self::getClassMethods($reflectionClass) as $method) {
$code .= self::generateMethod($method);
Expand Down

0 comments on commit f53b07e

Please sign in to comment.