Skip to content

Commit 24fca74

Browse files
authored
Fixed broken HTMLTypeTest (#1945)
1 parent 5af4345 commit 24fca74

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/lib/types/src/Flow/Types/Value/HTMLDocument.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ final class HTMLDocument implements \Stringable
1212

1313
public function __construct(string|object $value)
1414
{
15-
if (\is_string($value)) {
15+
if ('' === $value) {
16+
$this->value = $value;
17+
} elseif (\is_string($value)) {
1618
if (\class_exists('\Dom\HTMLDocument', false)) {
1719
$options = \LIBXML_HTML_NOIMPLIED;
1820

src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
use function Flow\Types\DSL\{type_from_array, type_html};
88
use Flow\Types\Exception\{CastingException, InvalidTypeException};
9+
use Flow\Types\Value\HTMLDocument;
910
use PHPUnit\Framework\Attributes\DataProvider;
1011
use PHPUnit\Framework\TestCase;
1112

1213
final class HTMLTypeTest extends TestCase
1314
{
1415
public static function assert_data_provider() : \Generator
1516
{
16-
yield 'valid \DOMDocument' => [
17-
'value' => new \DOMDocument,
17+
yield 'valid HTMLDocument' => [
18+
'value' => new HTMLDocument(''),
1819
'exceptionClass' => null,
1920
];
2021

@@ -66,7 +67,6 @@ public static function cast_data_provider() : \Generator
6667
'expected' => <<<'HTML'
6768
<!DOCTYPE html>
6869
<html lang="en"><body><div><span>1</span></div></body></html>
69-
7070
HTML,
7171
'exceptionClass' => null,
7272
];
@@ -75,7 +75,6 @@ public static function cast_data_provider() : \Generator
7575
'value' => '<div><span>1</span></div>',
7676
'expected' => <<<'HTML'
7777
<div><span>1</span></div>
78-
7978
HTML,
8079
'exceptionClass' => null,
8180
];
@@ -89,8 +88,8 @@ public static function cast_data_provider() : \Generator
8988

9089
public static function is_valid_data_provider() : \Generator
9190
{
92-
yield 'valid \DOMDocument' => [
93-
'value' => new \DOMDocument(),
91+
yield 'valid HTMLDocument' => [
92+
'value' => new HTMLDocument(''),
9493
'expected' => true,
9594
];
9695

@@ -117,7 +116,7 @@ public function test_assert(mixed $value, ?string $exceptionClass = null) : void
117116
$this->expectException($exceptionClass);
118117
type_html()->assert($value);
119118
} else {
120-
self::assertInstanceOf(\DOMDocument::class, type_html()->assert($value));
119+
self::assertInstanceOf(HTMLDocument::class, type_html()->assert($value));
121120
}
122121
}
123122

@@ -129,7 +128,7 @@ public function test_cast(mixed $value, mixed $expected, ?string $exceptionClass
129128
type_html()->cast($value);
130129
} else {
131130
$result = type_html()->cast($value);
132-
self::assertSame($expected, $result->saveHtml());
131+
self::assertSame($expected, $result->toString());
133132
}
134133
}
135134

0 commit comments

Comments
 (0)