generated from archtechx/template
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support defining #[Meta] on traits (resolve #9)
- Loading branch information
Showing
2 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
} |