From bc532d53dcb0a04e5b495ffa416c8520061d0bab Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Thu, 15 Feb 2024 08:45:17 +0100 Subject: [PATCH] Add the Property attribute --- composer.json | 4 +-- tests/PropertyAttributeTest.php | 27 ++++++++++++++++++++ tests/data/ClassPropertyAttribute.php | 27 ++++++++++++++++++++ tests/data/InvalidClassPropertyAttribute.php | 17 ++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/PropertyAttributeTest.php create mode 100644 tests/data/ClassPropertyAttribute.php create mode 100644 tests/data/InvalidClassPropertyAttribute.php diff --git a/composer.json b/composer.json index 0615327..1182ef5 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,8 @@ "prefer-stable": true, "require": { "php": ">=8.0", - "php-static-analysis/attributes": "^0.1.2 || dev-main", - "php-static-analysis/node-visitor": "^0.1.2 || dev-main", + "php-static-analysis/attributes": "^0.1.3 || dev-main", + "php-static-analysis/node-visitor": "^0.1.3 || dev-main", "phpstan/phpstan": "^1.8" }, "require-dev": { diff --git a/tests/PropertyAttributeTest.php b/tests/PropertyAttributeTest.php new file mode 100644 index 0000000..97707a8 --- /dev/null +++ b/tests/PropertyAttributeTest.php @@ -0,0 +1,27 @@ +analyse(__DIR__ . '/data/ClassPropertyAttribute.php'); + $this->assertCount(0, $errors); + } + + public function testInvalidClassPropertyAttribute(): void + { + $errors = $this->analyse(__DIR__ . '/data/InvalidClassPropertyAttribute.php'); + + $expectedErrors = [ + 'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16' => 7, + 'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55' => 7, + 'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36' => 7, + 'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Property constructor expects string, int given.' => 7, + 'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12, + ]; + + $this->checkExpectedErrors($errors, $expectedErrors); + } +} diff --git a/tests/data/ClassPropertyAttribute.php b/tests/data/ClassPropertyAttribute.php new file mode 100644 index 0000000..d1bdd8e --- /dev/null +++ b/tests/data/ClassPropertyAttribute.php @@ -0,0 +1,27 @@ +name; +$bar = $class->age; +$indexes = $class->index1 + $class->index2; diff --git a/tests/data/InvalidClassPropertyAttribute.php b/tests/data/InvalidClassPropertyAttribute.php new file mode 100644 index 0000000..5deb135 --- /dev/null +++ b/tests/data/InvalidClassPropertyAttribute.php @@ -0,0 +1,17 @@ +