bruli/php-git-hooks

Coverage not working

danitome24 opened this issue · 5 comments

Hi,

I'm using this package on my project and I have a problem when I run pre-commit hook with phpunit and coverage guard enabled. First of all let me tell you which versions am I using:

phpunit: v6,
php-git-hooks: v5.1

Then my php-git-hooks config looks like this:

pre-commit:
    enabled: true
    execute:
        composer: true
        jsonlint: false
        phplint: true
        phpmd:
            enabled: true
            options: null
        phpcs:
            enabled: true
            standard: PSR2
            ignore: '(tests/*|Migrations/*)'
        php-cs-fixer:
            enabled: true
            levels:
                psr0: true
                psr1: true
                psr2: true
                symfony: true
            options: null
        phpunit:
            enabled: true
            random-mode: false
            options: null
            strict-coverage:
                enabled: false
                minimum: null
            guard-coverage:
                enabled: true
                message: 'WARNING!!, your code coverage is lower.'
    message:
        right-message: 'HEY, GOOD JOB!!'
        error-message: 'FIX YOUR FUCKING CODE!!'
commit-msg:
    enabled: true
    regular-expression: '#[0-9]{1,7}'
pre-push:
    enabled: false
    execute:
        phpunit:
            enabled: true
            random-mode: false
            options: null
            strict-coverage:
                enabled: false
                minimum: null
            guard-coverage:
                enabled: true
                message: 'WARNING!!, your code coverage is lower.'
    message:
        right-message: 'PUSH IT!!'
        error-message: 'YOU CAN NOT PUSH CODE!!'

As you can see, I have phpunit enabled and also guard coverage. Otherwise, the guard coverage is not working for me. It generates the file .guard_clause with a 0 inside and in the hook it always display a 0% and this is wrong 😢 . Debugging through the code I've found the cli for this: $command = 'php '.$tool.' --coverage-text|grep Classes|cut -d " " -f *4*|cut -d "%" -f 1'; (file: StrictCoverageProcessor, line: 32). Testing this line on my cli outputs nothing, but If I change this line into this: $command = 'php '.$tool.' --coverage-text|grep Classes|cut -d " " -f *5*|cut -d "%" -f 1'; it works! (Look the first cut -f).

I'm the only who is dealing with this?

Thanks!!!

bruli commented

I'm testing and:

 bin/phpunit --coverage-text|grep Classes|cut -d " " -f 4|cut -d "%" -f 1 
100.00
 bin/phpunit --coverage-text|grep Classes|cut -d " " -f 5|cut -d "%" -f 1 
(208/208)

I can't understand witch your problem.

Perfect!! I'll send you a PR

bruli commented

Maybe the problem is when you have not a coverage?

Nop, I have coverage working but the value is not cutted well

Merged! Thanks