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

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

Merged
merged 1 commit into from
Jan 25, 2024
Merged

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

merged 1 commit into from
Jan 25, 2024

Conversation

JonPurvis
Copy link
Contributor

@JonPurvis JonPurvis commented Nov 13, 2023

What:

  • Bug Fix
  • New Feature

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:

  • toBeStringBackedEnum()
  • toBeIntBackedEnum()
<?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: pestphp/docs#247

@JonPurvis JonPurvis changed the title Add toBeBackedEnum() Expectation Add toBeBackedEnum() Architecture Expectation Nov 13, 2023
@devajmeireles devajmeireles changed the title Add toBeBackedEnum() Architecture Expectation [2.x] Add toBeBackedEnum() Architecture Expectation Nov 16, 2023
@JonPurvis JonPurvis changed the title [2.x] Add toBeBackedEnum() Architecture Expectation [2.x] Add toBeStringBackedEnum() and toBeIntBackedEnum() Architecture Expectations Nov 18, 2023
@JonPurvis
Copy link
Contributor Author

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
Copy link
Contributor

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 pestphp/pest-plugin-type-coverage#15. Just waiting to be merged!

@JonPurvis
Copy link
Contributor Author

Awesome, thanks for letting me know @faissaloux 😄

@JonPurvis
Copy link
Contributor Author

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 pestphp/pest-plugin-type-coverage#17

Thanks!

@JonPurvis
Copy link
Contributor Author

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

@nunomaduro nunomaduro merged commit 607a490 into pestphp:2.x Jan 25, 2024
18 of 20 checks passed
@JonPurvis
Copy link
Contributor Author

Thank you! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants