Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 41 additions & 0 deletions tests/MiscCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<blockquote>Quoted content here.</blockquote>';
$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('<h1>Hello</h1>', ['elements' => ['h1' => false]]);
static::assertSame('Hello', $html2text->getText());
}
}