|
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; |
@@ -89,17 +90,13 @@ final class PhptTestCase implements Reorderable, SelfDescribing, Test |
89 | 90 | */ |
90 | 91 | public function __construct(string $filename, ?AbstractPhpProcess $phpUtil = null) |
91 | 92 | { |
92 | | - if (!is_file($filename)) { |
93 | | - throw new Exception( |
94 | | - sprintf( |
95 | | - 'File "%s" does not exist.', |
96 | | - $filename, |
97 | | - ), |
98 | | - ); |
99 | | - } |
| 93 | + $this->ensureFileExists($filename); |
100 | 94 |
|
101 | 95 | $this->filename = $filename; |
102 | | - $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); |
| 96 | + |
| 97 | + $this->ensureCoverageFileDoesNotExist(); |
| 98 | + |
| 99 | + $this->phpUtil = $phpUtil ?: AbstractPhpProcess::factory(); |
103 | 100 | } |
104 | 101 |
|
105 | 102 | /** |
@@ -657,7 +654,7 @@ private function cleanupForCoverage(): RawCodeCoverageData |
657 | 654 | $buffer = @file_get_contents($files['coverage']); |
658 | 655 |
|
659 | 656 | if ($buffer !== false) { |
660 | | - $coverage = @unserialize($buffer); |
| 657 | + $coverage = @unserialize($buffer, ['allowed_classes' => false]); |
661 | 658 |
|
662 | 659 | if ($coverage === false) { |
663 | 660 | $coverage = RawCodeCoverageData::fromXdebugWithoutPathCoverage([]); |
@@ -862,4 +859,37 @@ private function settings(bool $collectCoverage): array |
862 | 859 |
|
863 | 860 | return $settings; |
864 | 861 | } |
| 862 | + |
| 863 | + /** |
| 864 | + * @throws Exception |
| 865 | + */ |
| 866 | + private function ensureFileExists(string $filename): void |
| 867 | + { |
| 868 | + if (!is_file($filename)) { |
| 869 | + throw new Exception( |
| 870 | + sprintf( |
| 871 | + 'File "%s" does not exist.', |
| 872 | + $filename, |
| 873 | + ), |
| 874 | + ); |
| 875 | + } |
| 876 | + } |
| 877 | + |
| 878 | + /** |
| 879 | + * @throws Exception |
| 880 | + */ |
| 881 | + private function ensureCoverageFileDoesNotExist(): void |
| 882 | + { |
| 883 | + $files = $this->getCoverageFiles(); |
| 884 | + |
| 885 | + if (file_exists($files['coverage'])) { |
| 886 | + throw new Exception( |
| 887 | + sprintf( |
| 888 | + 'File %s exists, PHPT test %s will not be executed', |
| 889 | + $files['coverage'], |
| 890 | + $this->filename, |
| 891 | + ), |
| 892 | + ); |
| 893 | + } |
| 894 | + } |
865 | 895 | } |
0 commit comments