diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d668d1..d267ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### 5.0.5 (2026-04-24) + +- 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) - fix errors reported by phpstan 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('

Hello

', ['elements' => ['h1' => false]]); + static::assertSame('Hello', $html2text->getText()); + } }