Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial compatability support for PHP8.2 for readonly classes. #564

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions fixtures/ReadOnlyClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Fixtures\Prophecy;

readonly class ReadOnlyClass
{
}
6 changes: 6 additions & 0 deletions src/Prophecy/Doubler/Generator/ClassMirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ private function reflectClassToNode(ReflectionClass $class, Node\ClassNode $node
), $class);
}

if (method_exists(ReflectionClass::class, 'isReadOnly') && true === $class->isReadOnly()) {
throw new ClassMirrorException(sprintf(
'Could not reflect class %s. Doubling a readonly class is not supported yet.', $class->getName()
), $class);
}

$node->setParentClass($class->getName());

foreach ($class->getMethods(ReflectionMethod::IS_ABSTRACT) as $method) {
Expand Down
17 changes: 17 additions & 0 deletions tests/Doubler/Generator/ClassMirrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,21 @@ public function it_can_not_double_intersection_argument_types()

$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\IntersectionArgumentType'), []);
}

/**
* @test
*/
public function it_throws_an_exception_if_class_is_readonly()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('Classes marked readonly are not supported in this PHP version.');
}

$this->expectException(ClassMirrorException::class);
$this->expectExceptionMessageMatches(
'/Could not reflect class [^\.]*.\. Doubling a readonly class is not supported yet./'
);

$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\ReadOnlyClass'), []);
}
}