Skip to content

Commit

Permalink
Test one attribute with an attribute with multiple different values (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
spaze committed Jan 11, 2024
2 parents 90fdf80 + 44ffd4d commit 3d18e0f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
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

0 comments on commit 3d18e0f

Please sign in to comment.