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

Test one attribute with an attribute with multiple different values #240

Merged
merged 1 commit into from
Jan 11, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/Usages/AttributeUsagesAllowParamsInAllowedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public function testRule(): void
],
[
'Attribute Attributes\AttributeEntity is forbidden.',
22,
25,
],
[
'Attribute Attributes\AttributeEntity is forbidden.',
28,
31,
],
[
'Attribute Attributes\AttributeEntity is forbidden.',
42,
45,
],
]);
}
Expand Down
25 changes: 23 additions & 2 deletions tests/Usages/AttributeUsagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Spaze\PHPStan\Rules\Disallowed\Usages;

use Attributes\AttributeColumn;
use Attributes\AttributeEntity;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
Expand Down Expand Up @@ -33,6 +34,22 @@ protected function getRule(): Rule
[
'attribute' => '#[\Attributes\AttributeClass()]',
],
[
'attribute' => AttributeColumn::class,
'message' => 'use `utc_datetime_immutable` instead.',
'allowExceptCaseInsensitiveParams' => [
[
'name' => 'type',
'position' => 2,
'value' => 'datetime',
],
[
'name' => 'type',
'position' => 2,
'value' => 'datetime_immutable',
],
],
],
]
);
}
Expand Down Expand Up @@ -60,13 +77,17 @@ public function testRule(): void
'Attribute Attributes\AttributeEntity is forbidden.',
18,
],
[
'Attribute Attributes\AttributeColumn is forbidden, use `utc_datetime_immutable` instead.',
21,
],
[
'Attribute Attributes\AttributeClass is forbidden.',
40,
43,
],
[
'Attribute Attributes\AttributeEntity is forbidden.',
42,
45,
],
]);

Expand Down
16 changes: 16 additions & 0 deletions tests/src/AttributeColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types = 1);

namespace Attributes;

#[Attribute]
class AttributeColumn
{

public function __construct(
?string $name = null,
?string $type = null
) {
}

}
3 changes: 3 additions & 0 deletions tests/src/ClassWithAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ClassWithAttributes
#[AttributeEntity]
public static $pepper = 'ofc';

#[AttributeColumn(name: 'start_date_parsed', type: 'datetime')]
private $fries = 'large';


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