Skip to content

Commit

Permalink
Test attribute args are catched
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas authored Jan 12, 2024
2 parents 9766ba1 + 3afaa5a commit 753b78a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/FixtureClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function doSomething(string $modelClass)
return new $modelClass();
}

#[SimpleAttribute]
#[SimpleAttribute(SimpleClass::class)]
public function methodWithAllAttributes(#[SimpleAttribute] int $number): int
{
$fn1 = #[SimpleAttribute] function (int $a) {
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/Simple/SimpleAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
namespace Tests\PHPat\fixtures\Simple;

#[\Attribute(\Attribute::TARGET_ALL)]
class SimpleAttribute {}
class SimpleAttribute {
public function __construct(public ?string $something = null) {
}
}
2 changes: 2 additions & 0 deletions tests/unit/rules/CanOnlyDepend/ConstantUseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
use Tests\PHPat\fixtures\FixtureClass;
use Tests\PHPat\fixtures\Simple\SimpleClass;
use Tests\PHPat\fixtures\Special\ClassWithConstant;
use Tests\PHPat\fixtures\Special\ClassWithConstantTwo;
use Tests\PHPat\unit\FakeTestParser;
Expand All @@ -28,6 +29,7 @@ public function testRule(): void
{
$this->analyse(['tests/fixtures/FixtureClass.php'], [
[sprintf('%s should not depend on %s', FixtureClass::class, ClassWithConstant::class), 54],
[sprintf('%s should not depend on %s', FixtureClass::class, SimpleClass::class), 94],
]);
}

Expand Down

0 comments on commit 753b78a

Please sign in to comment.