Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/CoreGenericAttributes.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class AllowDynamicProperties
}

/** @psalm-immutable */
#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)]
final class Override
{
public function __construct() {}
Expand Down
38 changes: 38 additions & 0 deletions tests/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ class Foo {}
public function providerValidCodeParse(): iterable
{
return [
'overrideAttributeOnOverriddenMethod' => [
'code' => '<?php
class A
{
public function f(): void {}
}

class B extends A
{
#[\Override]
public function f(): void {}
}',
],
'overrideAttributeOnOverriddenProperty' => [
'code' => '<?php
class A
{
protected int $x = 1;
}

class B extends A
{
#[\Override]
protected int $x = 2;
}',
],
'classAndPropertyAttributesExists' => [
'code' => '<?php
namespace Foo;
Expand Down Expand Up @@ -738,6 +764,18 @@ class Foo
',
'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:39 - Attribute Attr cannot be used on a class constant',
],
'getAttributesOnClassConstantWithOverrideAttribute' => [
'code' => '<?php
class Foo
{
public const BAR = "baz";
}

$r = new ReflectionClassConstant(Foo::class, "BAR");
$r->getAttributes(\Override::class);
',
'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:39 - Attribute Override cannot be used on a class constant',
],
'getAttributesOnParameterWithNonParameterAttribute' => [
'code' => '<?php
#[Attribute(Attribute::TARGET_PROPERTY)]
Expand Down
Loading