mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 12:54:04 +00:00
Support defining #[Meta] on traits (resolve #9)
This commit is contained in:
parent
f0ea4c36c8
commit
365b3447f5
2 changed files with 53 additions and 5 deletions
37
tests/Pest/TraitTest.php
Normal file
37
tests/Pest/TraitTest.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
use ArchTech\Enums\Metadata;
|
||||
|
||||
test('enums can use traits which define meta properties on themselves', function () {
|
||||
expect(MyEnum::FOO->description())->toBe('Foo!');
|
||||
expect(MyEnum::BAR->description())->toBe('Bar!');
|
||||
expect(MyEnum::BAZ->description())->toBe(null);
|
||||
});
|
||||
|
||||
enum MyEnum
|
||||
{
|
||||
use Metadata;
|
||||
use HasDescription;
|
||||
|
||||
#[Description('Foo!')]
|
||||
case FOO;
|
||||
|
||||
#[Description('Bar!')]
|
||||
case BAR;
|
||||
|
||||
case BAZ;
|
||||
}
|
||||
|
||||
#[Attribute]
|
||||
class Description extends MetaProperty
|
||||
{}
|
||||
|
||||
/**
|
||||
* @method string|null description()
|
||||
*/
|
||||
#[Meta(Description::class)]
|
||||
trait HasDescription
|
||||
{
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue