Skip to content

Commit 2c53d08

Browse files
committed
add test for final and finalByKeyword() method
1 parent e940418 commit 2c53d08

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/PHPStan/Reflection/ClassReflectionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use PHPUnit\Framework\Attributes\RequiresPhp;
3535
use PHPUnit\Framework\TestCase;
3636
use ReflectionClass;
37+
use SomeNamespace\ClassWithConstants;
3738
use WrongClassConstantFile\SecuredRouter;
3839
use function array_map;
3940
use function array_values;
@@ -191,6 +192,19 @@ public function testDeprecatedConstantFromAnotherFile(): void
191192
$this->assertTrue($constant->isDeprecated()->yes());
192193
}
193194

195+
public function testFinalConstant(): void
196+
{
197+
$reflectionProvider = self::createReflectionProvider();
198+
$reflection = $reflectionProvider->getClass(ClassWithConstants::class);
199+
$constant = $reflection->getConstant('FINAL_FROM_DOCBLOCK');
200+
$this->assertTrue($constant->isFinal());
201+
$this->assertFalse($constant->isFinalByKeyword());
202+
203+
$constant = $reflection->getConstant('NATIVE_FINAL');
204+
$this->assertTrue($constant->isFinal());
205+
$this->assertTrue($constant->isFinalByKeyword());
206+
}
207+
194208
/**
195209
* @param class-string $className
196210
* @param array<class-string, class-string> $expected
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace SomeNamespace;
4+
5+
class ClassWithConstants
6+
{
7+
/**
8+
* @final
9+
*/
10+
public const FINAL_FROM_DOCBLOCK = 'final from docblock';
11+
12+
public final const NATIVE_FINAL = 'native final';
13+
}

0 commit comments

Comments
 (0)