Skip to content

Commit

Permalink
Tests: work around PHPUnit hard-failing on unknown class
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Nov 27, 2023
1 parent 5dd7d38 commit 8b859f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"require-dev": {
"brianium/paratest": "^6.3.0",
"cweagans/composer-patches": "^1.7",
"infection/infection": "^0.26.0",
"orisai/coding-standard": "^3.0.0",
"phpstan/extension-installer": "^1.0.0",
Expand Down Expand Up @@ -60,7 +61,8 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"cweagans/composer-patches": true
}
}
}
29 changes: 29 additions & 0 deletions tests/Patches/coverage-invalid-file-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 085e85e23d86b49cae114fcbe322325462c058cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Barto=C5=A1?= <[email protected]>
Date: Fri, 23 Dec 2022 16:27:23 +0100
Subject: [PATCH] Fix coverage failure in case of an invalid file

---
src/CodeCoverage.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php
index c35f27c8..9340f673 100644
--- a/src/CodeCoverage.php
+++ b/src/CodeCoverage.php
@@ -550,7 +550,11 @@ private function processUncoveredFilesFromFilter(): void

foreach ($uncoveredFiles as $uncoveredFile) {
if ($this->filter->isFile($uncoveredFile)) {
- include_once $uncoveredFile;
+ try {
+ include_once $uncoveredFile;
+ } catch (\Error $e) {
+ // Include may fail if file content is not valid (due to implementing/extending non-existent class, ...)
+ }
}
}

--
2.34.1.windows.1

0 comments on commit 8b859f0

Please sign in to comment.