Skip to content

Commit

Permalink
Cleanup/Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed Apr 18, 2022
1 parent ae4b21c commit cfd1585
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class Convert

public function __construct(string $htmlCode)
{
$this->htmlCode = $htmlCode;

$this->convertHtmlEntities();

$oDom = new DOMDocument();
$oDom->loadHTML($htmlCode);
$oDom->loadHTML($this->htmlCode);
$this->htmlCode = trim($oDom->textContent);

$this->convertHtmlEntities();
$this->parse();
}

Expand Down
15 changes: 10 additions & 5 deletions tests/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public function testConvertHtmlParagraph(): void
This is a paragraph.
TEXT;

$this->html2Text = new Html2Text($htmlCode);
$actual = $this->html2Text->getText();

$actual = (new Html2Text($htmlCode))->getText();
$this->assertSame($expectedOutput, $actual);
}

Expand Down Expand Up @@ -51,9 +49,16 @@ public function testConvertHtmlBody(): void
Hello World.
TEXT;

$this->html2Text = new Html2Text($htmlDocument);
$actual = $this->html2Text->getText();
$actual = (new Html2Text($htmlDocument))->getText();

$this->assertSame($expectedOutput, $actual);
}

public function testHtmlCodeContainingHtmlEntities(): void
{
$htmlCode = 'Hi, You';
$actual = (new Html2Text($htmlCode))->getText();

$this->assertSame('Hi, You', $actual);
}
}

0 comments on commit cfd1585

Please sign in to comment.