bruli / php-git-hooks

Git hooks for PHP projects
MIT License
676 stars 107 forks source link

Coverage not working #102

Closed danitome24 closed 6 years ago

danitome24 commented 7 years ago

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 7 years ago

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.

danitome24 commented 7 years ago

Perfect!! I'll send you a PR

bruli commented 7 years ago

Maybe the problem is when you have not a coverage?

danitome24 commented 7 years ago

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

danitome24 commented 6 years ago

Merged! Thanks