Skip to content

Commit

Permalink
Rename attribute tests and drop ClassWithAttributesAllow (#230)
Browse files Browse the repository at this point in the history
... which was a copy of `ClassWithAttributes` but with wrong comments. Instead of making the comments right, I've dropped it and had to split and rename some tests.
  • Loading branch information
spaze committed Dec 12, 2023
2 parents bf6aa80 + 41aee05 commit 240a2b5
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 138 deletions.
55 changes: 55 additions & 0 deletions tests/Usages/AttributeUsagesAllowInPathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types = 1);

namespace Spaze\PHPStan\Rules\Disallowed\Usages;

use Attributes\AttributeEntity;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use Spaze\PHPStan\Rules\Disallowed\DisallowedAttributeFactory;
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedAttributeRuleErrors;

class AttributeUsagesAllowInPathTest extends RuleTestCase
{

protected function getRule(): Rule
{
$container = self::getContainer();
return new AttributeUsages(
$container->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',
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' => [
[
Expand All @@ -44,7 +38,7 @@ protected function getRule(): Rule
[
'attribute' => '#[\Attributes\AttributeClass()]',
'allowIn' => [
__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php',
__DIR__ . '/../src/ClassWithAttributes.php',
],
],
]
Expand All @@ -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.',
Expand All @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions tests/Usages/AttributeUsagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ protected function getRule(): Rule
'attribute' => [
AttributeEntity::class,
],
'allowIn' => [
__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php',
],
'allowParamsAnywhereAnyValue' => [
[
'position' => 1,
Expand All @@ -35,9 +32,6 @@ protected function getRule(): Rule
],
[
'attribute' => '#[\Attributes\AttributeClass()]',
'allowIn' => [
__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php',
],
],
]
);
Expand All @@ -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.',
Expand Down Expand Up @@ -75,7 +69,6 @@ public function testRule(): void
42,
],
]);
$this->analyse([__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php'], []);

$this->analyse([__DIR__ . '/../src/AttributesEverywhere.php'], [
[
Expand Down
47 changes: 47 additions & 0 deletions tests/src/ClassWithAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types = 1);

namespace Attributes;

use Waldo\Quux\Blade;

#[AttributeEntity]
class ClassWithAttributes
{

#[AttributeEntity]
private const MAYO = true;

#[AttributeEntity]
public $cheddar = 'plz';

#[AttributeEntity]
public static $pepper = 'ofc';


#[AttributeEntity(repositoryClass: UserRepository::class, readOnly: false)]
public function hasAvocado(): bool
{
}


#[AttributeEntity(UserRepository::class)]
public function hasTuna(): bool
{
}


#[AttributeEntity(Blade::class)]
public function hasKetchup(): bool
{
}


#[AttributeClass()]
public function hasPineapple(
#[AttributeEntity]
bool $really
): bool {
}

}
47 changes: 0 additions & 47 deletions tests/src/disallowed-allow/ClassWithAttributesAllow.php

This file was deleted.

47 changes: 0 additions & 47 deletions tests/src/disallowed/ClassWithAttributes.php

This file was deleted.

0 comments on commit 240a2b5

Please sign in to comment.