Running phpdbg to analyse "live" code coverage - php

I want to allow my testers to use the development website "as usual" and collect code coverages of every "run", combined everything and be able to say "after 4 hours of tests, here are the 75% of the code that were executed".
I use the php-code-coverage library (https://github.com/sebastianbergmann/php-code-coverage) and everything is working fine except that with xdebug as the tool used for code coverage it's way too slow (10 times slower that without activating php-code-coverage).
I've compiled my own version of php 7.2 with "--enable-phpdbg" and with the help of the command "update-alternatives" I'm able to run in cli :
$ php index.php
and get the code coverage I need, and it's only two times slower (every call to "php" is calling "phpdbg").
But I can't find a way to make it work with apache so that when I'm loading my website it's the executable "phpdbg" and not "php" that is used.
Even if I'm compiling my own ".so" it will still be "php" that will be executed.

Related

How to make phpunit faster on big bootstrap

I've tried opcache but it even makes it lower, in some cli programs there is a watch option, the cli keeps running that on changes it will redo something, I couldn't find that for phpunit.
Just to be clear, the tests are pretty fast, what's slow is the bootstrap because the codebase is rather big, the code base runs fine on a webserver thanks to opcache, but for phpunit opcache (which only should work with file cache I'd suppose?) seems to be hopeless...
I'm using PHP 8 and PHPUnit 9

Getting PHP lint / PhpStorm inspect errors every day from command line

Attempting to run a form of PHP linting from the command line, daily.
I've tried SonarLint - lovely in PhpStorm, but sadly they've apparently stopped supporting command line commands.
I tried to get PHPLint and php -l but I'm no php guru and was struggling with composer files.
Finally I looked at PhpStorm inspect - I can get it to create a directory of 99 types of errors, it seems, but then I'd have to either write a tool to grep the files and look /count errors, warnings to see if they're going up / down daily, or check it in the IDE, neither of which are particularly appealing.
There must be a tool that produces a nice simple output that I can incorporate as part of a build pipeline, graphing errors/warnings either daily or after each build?
Try PHPStan (PHP Static Analysis Tool), which supports CLI execution. This is also installed with composer (which is pretty much the default); most PHP IDE support composer out-of-the-box. Likely you won't find that many packages that won't be installed alike that, unless manually dropping them into an include path (this just won't give you the auto-loader capabilities).
You actually can run PhpStorm inspections from command line: https://www.jetbrains.com/help/phpstorm/command-line-code-inspector.html

How can i improve Codeception Code Coverage speed

Currently we have written some unit test for our php laravel 5.5 application using codeception. just for additional info, our laravel code base have around 200k LOC. For normal unit test run, we noticed that it is really fast in which we can get more than 200 tests to finish within 1 hour.
But the main issue is that when we enabled codecoverage in codeception which is using xdebug by default, we noticed the execution time increased drastically.
Now it already took 1 week but the whole codecoverage execution not even finished yet.
I am not sure whether this is the problem from codeception or xdebug itself but if anybody have experiences running php codecoverage on a huge codebase, it would be nice if you can share how you achieve it. Would appreciate it also if somebody can suggest any other tools to look into. Currently we are considering switching to phpunit but are still open to other tools to explore.
Replacing Codeception with PHPUnit will be a lot of work for little gain, because Codeception uses PHPUnit and its PHP-Code-Coverage library under the hood.
There is a new code coverage extension, called pcov which is supposedly much faster than xdebug.
https://github.com/krakjoe/pcov/blob/develop/INSTALL.md
I haven't tried to use it, but be aware that it requires PHPUnit 8, which is only available on PHP 7.2 or later versions.
Recently I have seen code coverage sped up by replacing xdebug with phpdbg - I can't give exact numbers as the code base has extensive functional tests in its test run (and the speed-up was only for unit tests), but a 2+ hour test and coverage run has been reduced to around 50 minutes.
Note that xdebug and phpdbg can differ in their code coverage (it looked like xdebug better dealt with opcache optimisations).
edit:
Since replacing xdebug with phpdbg, I have seen further speed improvements by replacing phpdbg with pcov.

Run PHPUnit without shell access to my php server

I seem to remember three years ago or so - the last time I looked into PHP - that it was simple to run PHP Unit tests.
However now I am looking around and I cant find any simple solution. Everything I try has too many requirements, either:
It requires shell access to the php server (to run from the command line)
Or I can use Visual PHP Unit but then I have a whole set of other requirements ...
see:
It requires Apache. (for .htaccess)
It requires OVERRIDE ALL
It requires PEAR
It requires a database
Is there a simpler way to run PHP Unit tests? Something that would just require PHP scripts and a browser? or at the most composer?
Something that would work in the average limited bare bones low budget hosting environment?

Using inclued php pecl extension

I'm currently trying to level up on my PHP debugging skills and as part of that I'm trying to learn several new tools. One of them is inclued.
The extension seemingly works fine (no startup error, shows up in phpinfo, generates dump files), but it always reports number of includes as 0, so something is clearly not working right.
At first I suspected this was related to my heavy use of auto_include, but after doing some tests which do not, I doubt that is related.
Class graphs are generated OK, but include maps simply don't exist. Am I simply Doing It Wrong, or is the extension broken? I just don't know and even after some heavy duty googling cannot find anything useful.
I installed inclued using the "phpize method". My PHP version is 5.3.2 running on Mac OSX 10.6.5. I also have XDebug and memtrack installed.
After doing a test run with valgrind watching Apache I noticed xdebug was operating below inclued. On a blind test I tried disabling XDebug and lo and behold: inclued works as expected.
So to answer my own question:
Don't use XDebug in conjunction with inclued if you want to have include graphs. Class graphing works fine with XDebug running.

Categories