Skip to content

Commit 4414975

Browse files
committed
Use set_error_handler() to consume iconv warning under PHPUnit.
1 parent 0b2d76d commit 4414975

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/View/CsvView.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,15 @@ protected function _transcode(string $csv, string $dataEncoding, string $csvEnco
485485
default => $csvEncoding,
486486
};
487487
// iconv() emits an E_NOTICE / E_WARNING immediately before returning
488-
// false on unconvertible input. Suppress just for this call so we
489-
// surface the failure via our own (strict-mode) exception below
490-
// rather than as two near-duplicate signals.
491-
$previousReporting = error_reporting();
492-
error_reporting($previousReporting & ~(E_NOTICE | E_WARNING));
488+
// false on unconvertible input. Install a no-op handler for the
489+
// duration of the call so we surface the failure via our own
490+
// (strict-mode) exception below rather than as two near-duplicate
491+
// signals. PHPUnit's own error handler is restored on `finally`.
492+
set_error_handler(static fn(): bool => true, E_NOTICE | E_WARNING);
493493
try {
494494
$converted = iconv($dataEncoding, $targetSpec, $csv);
495495
} finally {
496-
error_reporting($previousReporting);
496+
restore_error_handler();
497497
}
498498
if ($converted === false) {
499499
if ($mode === static::TRANSCODING_MODE_STRICT) {

0 commit comments

Comments
 (0)