Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better enum support in @testdox #5097

Closed
OskarStark opened this issue Nov 15, 2022 · 2 comments
Closed

Better enum support in @testdox #5097

OskarStark opened this issue Nov 15, 2022 · 2 comments
Labels
feature/data-provider Data Providers feature/testdox The TextDox printer/formatter type/enhancement A new idea that should be implemented

Comments

@OskarStark
Copy link
Contributor

While its more and more common to use native PHP enums in data providers, it would be nice if the @testdox annotation not just print the class, but the value.

Lets use the following example:

    /**
     * @test
     *
     * @dataProvider colorProvider
     * 
     * @testdox Color by string "$string" is $expected 
     */
    public function color(Color $expected, string $string): void
    {
        self::assertSame($expected, Color::byString($string);
    }

    public function colorProvider(): iterable
    {
        yield 'red' => [Color::RED, 'red'];
        yield 'blue' => [Color::RED, 'blue'];
    }

with the following enum:

namespace App\Enum;

enum Color: string
{
    case RED = 'red';
    case RED = 'blue';

    public function byString(string $string): self
    {    
        return match($string) {
            'red' => self::RED,
            'blue' => self::BLUE,
        };
    }
}

Right now the output of the @testdox annotation is:
Color by string "red" is App\Enum\Color

in case of a \BackedEnum, the following output would be more helpful:

- Color by string "red" is App\Enum\Color
+ Color by string "red" is App\Enum\Color::RED

I am willing to provide a PR if you can point me in the right direction

cc @localheinz as we talked about this already

@OskarStark OskarStark added the type/enhancement A new idea that should be implemented label Nov 15, 2022
@sebastianbergmann sebastianbergmann added feature/testdox The TextDox printer/formatter feature/data-provider Data Providers labels Nov 15, 2022
@OskarStark
Copy link
Contributor Author

Thank you very much @sebastianbergmann 🙏

That was fast 🥰

@rcsofttech85
Copy link

@OskarStark enum Color is invalid .
carbon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers feature/testdox The TextDox printer/formatter type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

3 participants