|
19 | 19 | use function explode; |
20 | 20 | use function extension_loaded; |
21 | 21 | use function file; |
| 22 | +use function file_exists; |
22 | 23 | use function file_get_contents; |
23 | 24 | use function file_put_contents; |
24 | 25 | use function is_array; |
|
31 | 32 | use function preg_split; |
32 | 33 | use function realpath; |
33 | 34 | use function rtrim; |
| 35 | +use function sprintf; |
34 | 36 | use function str_contains; |
35 | 37 | use function str_replace; |
36 | 38 | use function str_starts_with; |
@@ -89,7 +91,10 @@ final class PhptTestCase implements Reorderable, SelfDescribing, Test |
89 | 91 | public function __construct(string $filename, ?AbstractPhpProcess $phpUtil = null) |
90 | 92 | { |
91 | 93 | $this->filename = $filename; |
92 | | - $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); |
| 94 | + |
| 95 | + $this->ensureCoverageFileDoesNotExist(); |
| 96 | + |
| 97 | + $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); |
93 | 98 | } |
94 | 99 |
|
95 | 100 | /** |
@@ -654,7 +659,7 @@ private function cleanupForCoverage(): RawCodeCoverageData |
654 | 659 | } |
655 | 660 |
|
656 | 661 | if ($buffer !== false) { |
657 | | - $coverage = @unserialize($buffer); |
| 662 | + $coverage = @unserialize($buffer, ['allowed_class' => false]); |
658 | 663 |
|
659 | 664 | if ($coverage === false) { |
660 | 665 | $coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]); |
@@ -840,4 +845,22 @@ private function settings(bool $collectCoverage): array |
840 | 845 |
|
841 | 846 | return $settings; |
842 | 847 | } |
| 848 | + |
| 849 | + /** |
| 850 | + * @throws CodeCoverageFileExistsException |
| 851 | + */ |
| 852 | + private function ensureCoverageFileDoesNotExist(): void |
| 853 | + { |
| 854 | + $files = $this->getCoverageFiles(); |
| 855 | + |
| 856 | + if (file_exists($files['coverage'])) { |
| 857 | + throw new CodeCoverageFileExistsException( |
| 858 | + sprintf( |
| 859 | + 'File %s exists, PHPT test %s will not be executed', |
| 860 | + $files['coverage'], |
| 861 | + $this->filename, |
| 862 | + ), |
| 863 | + ); |
| 864 | + } |
| 865 | + } |
843 | 866 | } |
0 commit comments