diff --git a/tests/Usages/AttributeUsagesAllowInPathTest.php b/tests/Usages/AttributeUsagesAllowInPathTest.php new file mode 100644 index 0000000..46740a0 --- /dev/null +++ b/tests/Usages/AttributeUsagesAllowInPathTest.php @@ -0,0 +1,55 @@ +getByType(DisallowedAttributeRuleErrors::class), + $container->getByType(DisallowedAttributeFactory::class), + [ + [ + 'attribute' => [ + AttributeEntity::class, + ], + 'allowIn' => [ + __DIR__ . '/../src/ClassWithAttributes.php', + ], + ], + [ + 'attribute' => '#[\Attributes\AttributeClass()]', + 'allowIn' => [ + __DIR__ . '/../src/ClassWithAttributes.php', + ], + ], + ] + ); + } + + + public function testRule(): void + { + // Based on the configuration above, no errors in this file: + $this->analyse([__DIR__ . '/../src/ClassWithAttributes.php'], []); + } + + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + +} diff --git a/tests/Usages/AttributeUsagesAllowParamsMultipleTest.php b/tests/Usages/AttributeUsagesAllowParamsInAllowedTest.php similarity index 64% rename from tests/Usages/AttributeUsagesAllowParamsMultipleTest.php rename to tests/Usages/AttributeUsagesAllowParamsInAllowedTest.php index 8328459..84acc47 100644 --- a/tests/Usages/AttributeUsagesAllowParamsMultipleTest.php +++ b/tests/Usages/AttributeUsagesAllowParamsInAllowedTest.php @@ -10,7 +10,7 @@ use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedAttributeRuleErrors; use Waldo\Quux\Blade; -class AttributeUsagesAllowParamsMultipleTest extends RuleTestCase +class AttributeUsagesAllowParamsInAllowedTest extends RuleTestCase { protected function getRule(): Rule @@ -25,13 +25,7 @@ protected function getRule(): Rule AttributeEntity::class, ], 'allowIn' => [ - __DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php', - ], - 'allowParamsAnywhereAnyValue' => [ - [ - 'position' => 1, - 'name' => 'repositoryClass', - ], + __DIR__ . '/../src/ClassWithAttributes.php', ], 'allowParamsInAllowed' => [ [ @@ -44,7 +38,7 @@ protected function getRule(): Rule [ 'attribute' => '#[\Attributes\AttributeClass()]', 'allowIn' => [ - __DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php', + __DIR__ . '/../src/ClassWithAttributes.php', ], ], ] @@ -55,7 +49,7 @@ protected function getRule(): Rule public function testRule(): void { // Based on the configuration above, in this file: - $this->analyse([__DIR__ . '/../src/disallowed/ClassWithAttributes.php'], [ + $this->analyse([__DIR__ . '/../src/ClassWithAttributes.php'], [ [ // expect this error message: 'Attribute Attributes\AttributeEntity is forbidden.', @@ -74,32 +68,6 @@ public function testRule(): void 'Attribute Attributes\AttributeEntity is forbidden.', 18, ], - [ - 'Attribute Attributes\AttributeClass is forbidden.', - 40, - ], - [ - 'Attribute Attributes\AttributeEntity is forbidden.', - 42, - ], - ]); - $this->analyse([__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php'], [ - [ - 'Attribute Attributes\AttributeEntity is forbidden.', - 8, - ], - [ - 'Attribute Attributes\AttributeEntity is forbidden.', - 12, - ], - [ - 'Attribute Attributes\AttributeEntity is forbidden.', - 15, - ], - [ - 'Attribute Attributes\AttributeEntity is forbidden.', - 18, - ], [ 'Attribute Attributes\AttributeEntity is forbidden.', 22, diff --git a/tests/Usages/AttributeUsagesTest.php b/tests/Usages/AttributeUsagesTest.php index cc163a9..62bc8be 100644 --- a/tests/Usages/AttributeUsagesTest.php +++ b/tests/Usages/AttributeUsagesTest.php @@ -23,9 +23,6 @@ protected function getRule(): Rule 'attribute' => [ AttributeEntity::class, ], - 'allowIn' => [ - __DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php', - ], 'allowParamsAnywhereAnyValue' => [ [ 'position' => 1, @@ -35,9 +32,6 @@ protected function getRule(): Rule ], [ 'attribute' => '#[\Attributes\AttributeClass()]', - 'allowIn' => [ - __DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php', - ], ], ] ); @@ -47,7 +41,7 @@ protected function getRule(): Rule public function testRule(): void { // Based on the configuration above, in this file: - $this->analyse([__DIR__ . '/../src/disallowed/ClassWithAttributes.php'], [ + $this->analyse([__DIR__ . '/../src/ClassWithAttributes.php'], [ [ // expect this error message: 'Attribute Attributes\AttributeEntity is forbidden.', @@ -75,7 +69,6 @@ public function testRule(): void 42, ], ]); - $this->analyse([__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php'], []); $this->analyse([__DIR__ . '/../src/AttributesEverywhere.php'], [ [ diff --git a/tests/src/ClassWithAttributes.php b/tests/src/ClassWithAttributes.php new file mode 100644 index 0000000..9eccaae --- /dev/null +++ b/tests/src/ClassWithAttributes.php @@ -0,0 +1,47 @@ +