Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename attribute tests and drop ClassWithAttributesAllow #230

Merged
merged 1 commit into from
Dec 12, 2023
Merged
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
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.