1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 06:44:04 +00:00
enums/tests/Pest/TraitTest.php
Márk Magyar df3681965c
General code cleanup (#28)
* Add .idea folder to .gitignore

* Remove useless concatenation

* Add phpunit cache directory to .gitignore

* Use iterable type instead of unnecessary checks

* Remove unnecessary null coalescing

If the return value is `null`, it will return `null` anyway. If the method doesn't exist, it will throw an `Error` because of the undefined method.

* Add typehint

* Merge meta properties in one go instead of in a loop

* Simplify control flow

* Use non-deprecated phpstan configuration value

* Add missing types

* Fix style with php-cs-fixer

* Add tests that satisfy the ArrayIterator branch

* Use is() for comparison in in()

* from(int|string), tryFrom(int|string)

---------

Co-authored-by: Samuel Štancl <samuel@archte.ch>
2025-06-07 01:11:53 +02:00

39 lines
694 B
PHP

<?php
declare(strict_types=1);
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
{
}