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 compatibility support for PHP8.2 for DNF #565

Merged
merged 2 commits into from Nov 29, 2022
Merged
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
11 changes: 11 additions & 0 deletions fixtures/DnfArgumentType.php
@@ -0,0 +1,11 @@
<?php

namespace Fixtures\Prophecy;

class DnfArgumentType
{
public function doSomething ((A&B)|C $foo)
{

}
}
11 changes: 11 additions & 0 deletions fixtures/DnfReturnType.php
@@ -0,0 +1,11 @@
<?php

namespace Fixtures\Prophecy;

class DnfReturnType
{
public function doSomething () : (A&B)|C
{

}
}
7 changes: 7 additions & 0 deletions src/Prophecy/Doubler/Generator/ClassMirror.php
Expand Up @@ -227,6 +227,13 @@ private function getTypeHints(?ReflectionType $type, ?ReflectionClass $class, bo
}
elseif ($type instanceof ReflectionUnionType) {
$types = $type->getTypes();
if (\PHP_VERSION_ID >= 80200) {
foreach ($types as $reflectionType) {
if ($reflectionType instanceof ReflectionIntersectionType) {
throw new ClassMirrorException('Doubling intersection types is not supported', $class);
}
}
}
}
elseif ($type instanceof ReflectionIntersectionType) {
throw new ClassMirrorException('Doubling intersection types is not supported', $class);
Expand Down
29 changes: 29 additions & 0 deletions tests/Doubler/Generator/ClassMirrorTest.php
Expand Up @@ -639,6 +639,34 @@ public function it_can_not_double_intersection_argument_types()
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\IntersectionArgumentType'), []);
}

/**
* @test
*/
public function it_can_not_double_dnf_intersection_argument_types()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('DNF intersection types are not supported in this PHP version');
}

$this->expectException(ClassMirrorException::class);

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

/**
* @test
*/
public function it_can_not_double_dnf_intersection_return_types()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('DNF intersection types are not supported in this PHP version');
}

$this->expectException(ClassMirrorException::class);

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

/**
* @test
*/
Expand Down Expand Up @@ -668,4 +696,5 @@ public function it_reflects_read_only_class()

$this->assertTrue($classNode->isReadOnly());
}

}