swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

sdebug not detected as code coverage tool for phpunit

Open juslintek opened this issue 5 years ago • 5 comments

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error. Just run phpunit tests with xdebug.coverage_enable = true

  2. What did you expect to see? Code coverage results

  3. What did you see instead? Error: No code coverage driver is available

  4. What version of Swoole are you using (show your php --ri swoole)?

root@96e1ae8f53ab:/var/www/html# php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.2
Built => Aug  5 2020 11:42:03
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
http2 => enabled
pcre => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608


php --ri sdebug

sdebug

xdebug support => enabled
Version => 2.9.3-dev
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support

Debugger => enabled
IDE Key => DOCKER-MYG2-BACKEND

Directive => Local Value => Master Value
xdebug.coverage_enable => On => On
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.collect_assignments => Off => Off
xdebug.default_enable => On => On
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.halt_level => 0 => 0
xdebug.max_nesting_level => 500 => 500
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_output_dir => /var/www/html/storage/framework/cache/xdebug-profiles/ => /var/www/html/storage/framework/cache/xdebug-profiles/
xdebug.profiler_output_name => cachegrind.out.%R.%p => cachegrind.out.%R.%p
xdebug.profiler_enable_trigger => On => On
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_append => Off => Off
xdebug.remote_enable => On => On
xdebug.remote_host => host.docker.internal => host.docker.internal
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_log => no value => no value
xdebug.remote_log_level => 7 => 7
xdebug.idekey => DOCKER-MYG2-BACKEND => DOCKER-MYG2-BACKEND
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_addr_header => no value => no value
xdebug.remote_timeout => 200 => 200
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
xdebug.cli_color => 0 => 0
xdebug.scream => Off => Off
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.auto_trace => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
uname -a
Linux 96e1ae8f53ab 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
php -v
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
    with Sdebug v2.9.3-dev, Copyright (c) 2002-2020, by Derick Rethans
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2) 

juslintek avatar Aug 05 '20 14:08 juslintek

@juslintek In the Sdebug extension, we have changed the name of the xdebug extension to sdebug, so you should modify the phpunit source code, for example, in the file phpunit/php-code-coverage/src/Driver/Driver.php:

1

and in the file phpunit/php-code-coverage/src/Driver/Xdebug2Driver.php:

2

huanghantao avatar Aug 18 '20 09:08 huanghantao

But this way I will always have to use forked phpunit and phpunit-code-coverage libraries, because in phpunit library I will have to change which php-code-coverage package it uses and in php-code-coverage package will have to do suggested changes. As well noticed that it is not possible at the moment to extend phpunit in a way that it would override test runner with custom code coverage configurations. I guess it would be better to suggest Sdebug specific Driver via PR to them and meanwhile use forked versions I guess. But still would need to fork both. As well testrunner is inside phpunit library so would have to add sdebug check there also.

juslintek avatar Aug 24 '20 09:08 juslintek

Meh, it seams that the way is to use PCOV https://github.com/sebastianbergmann/phpunit/issues/4469#issuecomment-698388094 or another testing library.

leocavalcante avatar Sep 24 '20 14:09 leocavalcante

@juslintek You can refer to the fourth point of this article, compatible SDEBUG code coverage https://dengxiaolong.com/article/2020/05/perfect-unit-test-of-hyperf.html

zonghay avatar Dec 14 '20 02:12 zonghay

Hi, I've set it up using phpdbg :-) like that:

phpdbg -c$(php --ini | grep "Loaded Configuration File" | cut -d":" -f2 | xargs) -dauto_globals_jit=Off -qrr vendor/bin/phpunit --colors=always --coverage-clover=test-reports/phpunit.clover.xml --log-junit=test-reports/phpunit.junit.xml

juslintek avatar Mar 08 '21 13:03 juslintek