Skip to content

Commit

Permalink
Tests that final modifier when using a method from a trait is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Dec 2, 2023
1 parent e0f312c commit 9231247
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/unit/Fixture/TraitFixtureWithFinal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

trait SimpleTrait
{
protected function foo() {}
}

class TraitFixtureWithFinal
{
use SimpleTrait {
foo as final;
}
}
18 changes: 18 additions & 0 deletions test/unit/Reflection/ReflectionClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;
use Qux;
use ReflectionClass as CoreReflectionClass;
Expand Down Expand Up @@ -1617,6 +1618,23 @@ public function testMethodsFromTraits(): void
self::assertSame('TraitFixtureTraitC2', $classInfo->getMethod('d_renamed')->getDeclaringClass()->getName());
}

#[RequiresPhp('8.3')]
public function testMethodsFromTraitsWithFinal(): void
{
$reflector = new DefaultReflector(new SingleFileSourceLocator(
__DIR__ . '/../Fixture/TraitFixtureWithFinal.php',
$this->astLocator,
));

$classInfo = $reflector->reflectClass('TraitFixtureWithFinal');

self::assertTrue($classInfo->hasMethod('foo'));
self::assertTrue($classInfo->getMethod('foo')->isFinal());
self::assertFalse($classInfo->getMethod('foo')->isPrivate());
self::assertFalse($classInfo->getMethod('foo')->isProtected());
self::assertFalse($classInfo->getMethod('foo')->isPublic());
}

public function testMethodsFromTraitsWithConflicts(): void
{
$reflector = new DefaultReflector(new SingleFileSourceLocator(
Expand Down

0 comments on commit 9231247

Please sign in to comment.