pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.49k stars 343 forks source link

[2.x] Add `toBeStringBackedEnum()` and `toBeIntBackedEnum()` Architecture Expectations #1006

Closed JonPurvis closed 8 months ago

JonPurvis commented 10 months ago

What:

Description:

We already have the very handy toBeEnum() Arch Expectation, which is useful for Pure Enums. This PR adds 2 similar Expectations, specifically for Backed Enums:

<?php

namespace App\Enums;

enum TestEnum: string
{
    case Test = 'Test';
}

By writing the following test, we can ensure that it is actually a String Backed Enum.

test('enum is backed by string')
    ->expect('app\Enums')
    ->toBeStringBackedEnums();

We could also change the test if the Enum returned an Int:

test('enum is backed by int')
    ->expect('app\Enums')
    ->toBeIntBackedEnums();

Docs: https://github.com/pestphp/docs/pull/247

JonPurvis commented 10 months ago

Hey @owenvoke 👋

Do you have any idea whats up with the failing tests on this PR? Static Analysis is failing but doesn't seem to actually be related to this PR

PHPStan\Analyser\NodeScopeResolver::__construct(): Argument #9 ($signatureMapProvider) must be of type PHPStan\Reflection\SignatureMap\SignatureMapProvider, PHPStan\PhpDoc\PhpDocInheritanceResolver given, called in /home/runner/work/pest/pest/vendor/pestphp/pest-plugin-type-coverage/src/PHPStanAnalyser.php on line 71

Any help would be much appreciated!

Thanks

faissaloux commented 10 months ago

Hey @owenvoke 👋

Do you have any idea whats up with the failing tests on this PR? Static Analysis is failing but doesn't seem to actually be related to this PR

PHPStan\Analyser\NodeScopeResolver::__construct(): Argument #9 ($signatureMapProvider) must be of type PHPStan\Reflection\SignatureMap\SignatureMapProvider, PHPStan\PhpDoc\PhpDocInheritanceResolver given, called in /home/runner/work/pest/pest/vendor/pestphp/pest-plugin-type-coverage/src/PHPStanAnalyser.php on line 71

Any help would be much appreciated!

Thanks

I have fixed it in https://github.com/pestphp/pest-plugin-type-coverage/pull/15. Just waiting to be merged!

JonPurvis commented 10 months ago

Awesome, thanks for letting me know @faissaloux 😄

JonPurvis commented 10 months ago

Hey @devajmeireles

Would you be able to re-run the checks on this PR please? I believe the 2 failing ones should now pass thanks to https://github.com/pestphp/pest-plugin-type-coverage/pull/17

Thanks!

JonPurvis commented 10 months ago

Hey @nunomaduro 👋

Would you be open to having these 2 new Arch Expectations in Pest? I'm going through my open PR's before the end of the year in an effort to get them merged/closed.

I look forward to hearing from you!

Thanks

JonPurvis commented 8 months ago

Thank you! 🥳