pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Coverage not found in path

Open thomas-0816 opened this issue 1 year ago • 1 comments

What Happened

Running multiple processes of pest in parallel create a crash with "ShouldNotHappen" for "vendor/pestphp/pest/.temp/coverage.php". e.g. first process deletes the coverage.php from the second process

Using "--cache-directory=/tmp/foo" still writes coverage.php to "vendor/pestphp/pest/.temp/coverage.php".

Ideally, pest should not write into "vendor/*".

My recommendation:

  • write coverage.php to "--cache-directory" if given
  • if coverage.php cannot be written, stop with an error

How to Reproduce

e.g. use "--cache-directory=/tmp/foo" and make vendor/pestphp/pest/.temp/ readonly

Expectation:

  • coverage.php gets written to /tmp/foo/coverage.php

Output:

   Pest\Exceptions\ShouldNotHappen 

  This should not happen - please create an new issue here: https://github.com/pestphp/pest.

  Issue: Coverage not found in path: xxx/vendor/pestphp/pest/.temp/coverage.php.
  PHP version: 8.4.1
  Operating system: Linux

  at vendor/pestphp/pest/src/Exceptions/ShouldNotHappen.php:37
     33▕      * Creates a new instance of should not happen without a specific exception.
     34▕      */
     35▕     public static function fromMessage(string $message): ShouldNotHappen
     36▕     {
  ➜  37▕         return new ShouldNotHappen(new Exception($message));
     38▕     }
     39▕ }
     40▕ 

      +1 vendor frames 
  1   vendor/pestphp/pest/src/Support/Coverage.php:88
      Pest\Exceptions\ShouldNotHappen::fromMessage()
      +1 vendor frames 

  2   vendor/pestphp/pest/src/Plugins/Coverage.php:147
      Pest\Support\Coverage::report()
      +1 vendor frames 

Sample Repository

No response

Pest Version

3.6.0

PHP Version

8.4.1

Operation System

Linux

Notes

No response

thomas-0816 avatar Jan 02 '25 19:01 thomas-0816

A quick workaround might be:

vendor/pestphp/pest/src/Support/Coverage.php

final class Coverage
{
    /**
     * Returns the coverage path.
     */
    public static function getPath(): string
    {
        static $file = null;

        $file ??= tempnam(sys_get_temp_dir(), 'pest') . 'coverage.php';

        return $file;
    }

thomas-0816 avatar Jan 02 '25 20:01 thomas-0816