mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 12:54:04 +00:00
Metadata (#8)
* Metadata * Fix code style (php-cs-fixer) * Code style Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
cc5bba1912
commit
55478c4eb7
8 changed files with 400 additions and 46 deletions
|
|
@ -1,67 +1,63 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
use ArchTech\Enums\From;
|
||||
use ArchTech\Enums\InvokableCases;
|
||||
use ArchTech\Enums\Names;
|
||||
use ArchTech\Enums\Options;
|
||||
use ArchTech\Enums\Values;
|
||||
use ArchTech\Enums\{InvokableCases, Options, Names, Values, From, Metadata};
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
|
||||
uses(ArchTech\Enums\Tests\TestCase::class)->in('Pest');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||
|
|
||||
*/
|
||||
#[Attribute]
|
||||
class Color extends MetaProperty {}
|
||||
|
||||
expect()->extend('toBeOne', function () {
|
||||
return $this->toBe(1);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function something()
|
||||
#[Attribute]
|
||||
class Desc extends MetaProperty
|
||||
{
|
||||
// ..
|
||||
public static function method(): string
|
||||
{
|
||||
return 'description';
|
||||
}
|
||||
}
|
||||
|
||||
#[Attribute]
|
||||
class Instructions extends MetaProperty
|
||||
{
|
||||
public static string $method = 'help';
|
||||
|
||||
protected function transform(mixed $value): mixed
|
||||
{
|
||||
return 'Help: ' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method string description()
|
||||
* @method string color()
|
||||
*/
|
||||
#[Meta(Color::class, Desc::class)] // variadic syntax
|
||||
enum Status: int
|
||||
{
|
||||
use InvokableCases, Options, Names, Values, From;
|
||||
use InvokableCases, Options, Names, Values, From, Metadata;
|
||||
|
||||
#[Color('orange')] #[Desc('Incomplete task')]
|
||||
case PENDING = 0;
|
||||
|
||||
#[Color('green')] #[Desc('Completed task')]
|
||||
#[Instructions('Illegal meta property — not enabled on the enum')]
|
||||
case DONE = 1;
|
||||
}
|
||||
|
||||
#[Meta([Color::class, Desc::class, Instructions::class])] // array
|
||||
enum Role
|
||||
{
|
||||
use InvokableCases, Options, Names, Values, From;
|
||||
use InvokableCases, Options, Names, Values, From, Metadata;
|
||||
|
||||
#[Color('indigo')]
|
||||
#[Desc('Administrator')]
|
||||
#[Instructions('Administrators can manage the entire account')]
|
||||
case ADMIN;
|
||||
|
||||
#[Color('gray')]
|
||||
#[Desc('Read-only guest')]
|
||||
#[Instructions('Guest users can only view the existing records')]
|
||||
case GUEST;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue