bruli/php-git-hooks

The process "php bin/phpunit " exceeded the timeout of 60 seconds.

mazhack opened this issue · 6 comments

Hi,
when i run phpunit alone

$ bin/phpunit
PHPUnit 5.5.5 by Sebastian Bergmann and contributors.

...............................................................  63 / 232 ( 27%)
............................................................... 126 / 232 ( 54%)
............................................................... 189 / 232 ( 81%)
...........................................                     232 / 232 (100%)

Time: 1,12 minutes, Memory: 27,00MB

OK (232 tests, 488 assertions)

on commit:

$ git commit
Pre-Commit tool
Checking composer files...........................0K
Checking json files...............................0K
Running PHPLINT...................................0K
Checking PSR0 code style with PHP-CS-FIXER........0K
Checking PSR1 code style with PHP-CS-FIXER........0K
Checking PSR2 code style with PHP-CS-FIXER........0K
Running unit tests................................
PHPUnit 5.5.5 by Sebastian Bergmann and contributors.

...............................................................  63 / 232 ( 27%)
............................................................... 126 / 232 ( 54%)
.........................

  [Symfony\Component\Process\Exception\ProcessTimedOutException]      
  The process "php bin/phpunit " exceeded the timeout of 60 seconds.  

How to set timeout gt 60 seconds?

Thank you!!

bruli commented

Wow.
You have heavy unit tests.
I'm not sure, but maybe you can change timeout value in your cli/php.ini file.

Hi, thanks for the answer, I modify the php.ini and does not work.
I found the solution, is just add the line $process->setTimeout(0); to the PhpUnitProcessor class.

<?php

namespace PhpGitHooks\Module\PhpUnit\Infrastructure\Tool;

use PhpGitHooks\Module\PhpUnit\Model\PhpUnitProcessorInterface;
use Symfony\Component\Process\Process;

class PhpUnitProcessor extends AbstractPhpUnitProcessor implements PhpUnitProcessorInterface
{
    /**
     * @param $options
     *
     * @return bool
     */
    public function process($options)
    {
        $tool = sprintf('php %s %s', $this->toolPathFinder->find('phpunit'), $options);

        $process = new Process($tool);
        $process->setTimeout(0);

        return $this->runProcess($process);
    }
}

The \Symfony\Component\Process\Process define 60 secs for timeout by default

bruli commented

Ok.
Maybe there a better solution. I can review it.

Has any proper solution been already found? When running with coverage even smaller test units would take more than 60 seconds.

I think this issue deserves to be re-opened. I am not sure if this is a better idea but we can either pass the config in $options array or add an optional argument such as $config to the process method to pass configuration values. Or may be a helper method that we can add to the process class?

composer.json

"config": {
        "process-timeout": 0
    }