From 5e5e743b95fdf8548609d81c354bcf467f5ca9b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 00:30:49 +0000 Subject: [PATCH 1/2] Update CHANGELOG for 5.0.5 coverage improvement Agent-Logs-Url: https://github.com/voku/html2text/sessions/9a27afcd-8291-4133-9788-1e4e0ecb984e Co-authored-by: voku <264695+voku@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d668d1..ed97bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 5.0.5 (2026-04-24) + +- increase code coverage by adding tests for previously untested code paths + (method coverage: 64.71% → 82.35%, +17.64 pp) + + ### 5.0.4 (2020-09-20) - fix errors reported by phpstan From e77a03f09e22ad2049aa4472df6e01569d6616d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 01:04:01 +0000 Subject: [PATCH 2/2] Add 3 tests for previously uncovered branches; achieve 100% coverage; update CHANGELOG Agent-Logs-Url: https://github.com/voku/html2text/sessions/7f4a17e2-4261-4c27-8999-e8a1d667058d Co-authored-by: voku <264695+voku@users.noreply.github.com> --- CHANGELOG.md | 6 ++++-- tests/MiscCoverageTest.php | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed97bf5..d267ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,10 @@ ### 5.0.5 (2026-04-24) -- increase code coverage by adding tests for previously untested code paths - (method coverage: 64.71% → 82.35%, +17.64 pp) +- increase test coverage to 100% (lines and methods) + by covering the three previously unreachable branches in + `convertNested` (width-reduction path), `pregCallback` (unknown-element fallback), + and `convertElement` (no-options fallback) ### 5.0.4 (2020-09-20) diff --git a/tests/MiscCoverageTest.php b/tests/MiscCoverageTest.php index 6ab7aa0..8aaf6a1 100644 --- a/tests/MiscCoverageTest.php +++ b/tests/MiscCoverageTest.php @@ -197,4 +197,45 @@ public function testReplaceOptionWithCustomDelimiter(): void ); static::assertSame('Hello-World', $html2text->getText()); } + + // ------------------------------------------------------------------------- + // convertNested: width reduction (line 630) + // ------------------------------------------------------------------------- + + public function testNestedBlockquoteWithWidthReducesWidth(): void + { + // A blockquote processed with width > 0 triggers the width -= 2 branch + // inside convertNested (the previously uncovered line 630). + $html = '
Quoted content here.'; + $html2text = new Html2Text($html, ['width' => 80]); + $output = $html2text->getText(); + static::assertStringContainsString('Quoted content here', $output); + } + + // ------------------------------------------------------------------------- + // pregCallback: unknown element fallback (line 815) + // ------------------------------------------------------------------------- + + public function testPregCallbackUnknownElementReturnsEmpty(): void + { + // pregCallback returns '' when the element does not match any known + // handler and is not present in $options['elements'] (line 815). + $html2text = new Html2Text(''); + $ref = new \ReflectionMethod($html2text, 'pregCallback'); + $ref->setAccessible(true); + $result = $ref->invoke($html2text, ['element' => 'unknownelement', 'value' => 'test']); + static::assertSame('', $result); + } + + // ------------------------------------------------------------------------- + // convertElement: element not in options → return input unchanged (line 939) + // ------------------------------------------------------------------------- + + public function testConvertElementWithNoOptionsReturnsInputUnchanged(): void + { + // When an element's options entry is set to false/null, convertElement + // falls through to `return $str` (line 939) and returns the raw text. + $html2text = new Html2Text('