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

[Feature request]: Covers for class methods #1037

Open
julesgraus opened this issue Dec 16, 2023 · 1 comment
Open

[Feature request]: Covers for class methods #1037

julesgraus opened this issue Dec 16, 2023 · 1 comment
Labels

Comments

@julesgraus
Copy link

julesgraus commented Dec 16, 2023

What Happened

Before migrating to pest, I had @Covers statements in the docblocks above my test methods. I always have them refer to functions, not complete classes. e.g:

    /**
     * @covers \App\Something\Something\SomeClass::create
     * @return void
     */

This makes sure that when the test hits that create method, only those lines will show up as covered. Even tough that test may hit other methods in that class too. Helping me to show which code i intentionally tested. Pest however, does not seem to support that? I would only be able to use the ->covers method on a test, it, or describe block with class names, or function names, but not class methods?
So, I need something that allows me to do something similar as the @Covers example from above.
Now I migrated to pest, but lost this feature I had when just using phpunit :), Maybe I am missing something, please tell me.

How to Reproduce

N.A

Sample Repository

No response

Pest Version

2.28.1

PHP Version

8.2.11

Operation System

macOS

Notes

No response

@julesgraus julesgraus added the bug label Dec 16, 2023
@julesgraus julesgraus changed the title [Feature request]: [Feature request]: Covers for class methods Dec 16, 2023
@ragulka
Copy link

ragulka commented Jul 11, 2024

I also ran into this. It should not be too hard to add support for this, using callables:

it('works', function() {
   // test here...
})->covers([MyClass::class, 'myMethod']);

Unfortunately, it looks like the this is an upstream limitation. PHPUnit only added CoversMethod support in v11 (and pest is still using v10. Additionally, the Covers attributes in PHPUnit are only supported at class level, not at test level, and it looks like there are no plans to support the latter.

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

No branches or pull requests

2 participants