Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Coverage not found in path #1335

Open
thbley opened this issue Jan 2, 2025 · 1 comment
Open

[Bug]: Coverage not found in path #1335

thbley opened this issue Jan 2, 2025 · 1 comment
Labels

Comments

@thbley
Copy link

thbley commented Jan 2, 2025

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

@thbley thbley added the bug label Jan 2, 2025
@thbley
Copy link
Author

thbley commented Jan 2, 2025

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant