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

HTTP tests are not included in test coverage by pcov #657

Closed
salvisb opened this issue Jan 24, 2024 · 7 comments
Closed

HTTP tests are not included in test coverage by pcov #657

salvisb opened this issue Jan 24, 2024 · 7 comments

Comments

@salvisb
Copy link

salvisb commented Jan 24, 2024

Sail Version

1.21.2

Laravel Version

10.40.0

PHP Version

8.2.5

Operating System

macOS

OS Version

14.1.1

Description

Hi, we have several HTTP tests for checking controller logic. However, when running sail artisan test --coverage all of the controller classes has 0% coverage. Unit tests are showing up just fine. Could it be that unlike xdebug, pcov is not capable of measuring coverage of the HTTP tests? Or it's somehow configurable? Thanks!

Steps To Reproduce

  • Create a controller
  • Create a test for the controller
  • Run sail artisan test --coverage
  • Check the coverage report
@pb30
Copy link

pb30 commented Jan 24, 2024

Does this work as expected if you run the command outside of sail?

@salvisb
Copy link
Author

salvisb commented Jan 24, 2024

Does this work as expected if you run the command outside of sail?

Yes, it does work as expected in CI pipeline with xdebug.

@driesvints
Copy link
Member

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@salvisb
Copy link
Author

salvisb commented Jan 26, 2024

Hi @driesvints. Thank you for looking into this. I think I found explanation of why Http tests are ignored. In our app we have not only "app" directory (which contains controllers) but also "src" directory (which contains domain layer of the app). When I move controllers from the "app" dir to "src", they are included in code coverage correctly. Apparently PCOV ignores the "app" directory even though I have specified both paths in phpunit.xml configuration.

<coverage>
  <include>
    <directory suffix=".php">app</directory>
    <directory suffix=".php">src</directory>
  </include>
</coverage>

@driesvints
Copy link
Member

Hi @salvisb. Glad you found that. Does the coverage report work when you run the test command out of sail?

@salvisb
Copy link
Author

salvisb commented Jan 26, 2024

@driesvints as I wrote before, coverage report work as expected with xdebug (outside of Sail). I think the issue is purely with pcov configuration.

Update: Tried running pcov outside of Sail and it behaves the same way, i.e. tests in "app" are not included in coverage.

By the way @driesvints, is it possible to switch from pcov to xdebug for measuring code coverage in Sail?

@driesvints
Copy link
Member

From what I can tell the collision library first checks for pcov, then xdebug. I'm not sure if it can be forced to use xdebug. Since this is probably more a collision issue than sail, I suggest to open an issue on their tracker.

https://github.com/nunomaduro/collision/blob/v8.x/src/Coverage.php#L45

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

No branches or pull requests

3 participants