PHP test coverage

php.internals

Vinicius Dias

2 years ago
PHP doc article about writing tests [1] mentions gcov.php.net as the source to see the coverage, but this address is not available anymore. I believe this should be updated to show how the coverage can be found so people know where to focus their efforts if they want to contribute with tests. [1]: https://wiki.php.net/doc/articles/writing-tests

Florian Engelhardt

2 years ago
Hey there, On Fri, Dec 8, 2023 at 12:11 AM Vinicius Dias <carlosv775@gmail.com> wrote:
> PHP doc article about writing tests [1] mentions gcov.php.net as the > source to see the coverage, but this address is not available anymore. >
The code coverage report can be found at https://app.codecov.io/github/php/php-src
> I believe this should be updated to show how the coverage can be found > so people know where to focus their efforts if they want to contribute > with tests >
I will have a look, the page overall looks like it could need some love ;-) In the meantime if you are interested in writing tests, I once wrote a blog post about that topic at https://dev.to/realflowcontrol/growing-the-php-core-one-test-at-a-time-4g4k /Florian

Vinicius Dias

2 years ago
> The code coverage report can be found at https://app.codecov.io/github/php/php-src
Ah, perfect. Thank you for sharing. I will take a closer look after work, but something seems weird to me. Here[1] you see that ctype_alpha seems to be uncovered, but here[2] we can see that it's tested. [1]: https://app.codecov.io/github/php/php-src/blob/master/ext%2Fctype%2Fctype.c#L112 [2]: https://github.com/php/php-src/blob/master/ext/ctype/tests/ctype_alpha_basic.phpt
> I will have a look, the page overall looks like it could need some love ;-) > In the meantime if you are interested in writing tests, I once wrote a blog post about that topic at https://dev.to/realflowcontrol/growing-the-php-core-one-test-at-a-time-4g4k
Ah, that's great. Thank you for that! :-D

Niels Dossche

2 years ago
Hi On 08/12/2023 17:04, Vinicius Dias wrote:
>> The code coverage report can be found at https://app.codecov.io/github/php/php-src > > Ah, perfect. Thank you for sharing. I will take a closer look after > work, but something seems weird to me. Here[1] you see that > ctype_alpha seems to be uncovered, but here[2] we can see that it's > tested. > > [1]: https://app.codecov.io/github/php/php-src/blob/master/ext%2Fctype%2Fctype.c#L112 > [2]: https://github.com/php/php-src/blob/master/ext/ctype/tests/ctype_alpha_basic.phpt
You'll see this kind of stuff with macros. The coverage report shows "partially covered" code as uncovered due to a limitation. In this particular example, the parameter parsing code failure isn't tested, so it marks the whole macro as untested. You'll see this many times in the PHP codebase. Also for example for RETURN_THROWS: because that macro performs an assertion it's always in red because the assertion isn't hit in our testing (and that's a good thing because if it were hit then it means there's a bug). Kind regards Niels