diff --git a/src/lib/types/src/Flow/Types/Value/HTMLDocument.php b/src/lib/types/src/Flow/Types/Value/HTMLDocument.php index 3ee238d67a..9293bb085a 100644 --- a/src/lib/types/src/Flow/Types/Value/HTMLDocument.php +++ b/src/lib/types/src/Flow/Types/Value/HTMLDocument.php @@ -12,7 +12,9 @@ final class HTMLDocument implements \Stringable public function __construct(string|object $value) { - if (\is_string($value)) { + if ('' === $value) { + $this->value = $value; + } elseif (\is_string($value)) { if (\class_exists('\Dom\HTMLDocument', false)) { $options = \LIBXML_HTML_NOIMPLIED; diff --git a/src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php b/src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php index 63869914c6..31125ec054 100644 --- a/src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php +++ b/src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php @@ -6,6 +6,7 @@ use function Flow\Types\DSL\{type_from_array, type_html}; use Flow\Types\Exception\{CastingException, InvalidTypeException}; +use Flow\Types\Value\HTMLDocument; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -13,8 +14,8 @@ final class HTMLTypeTest extends TestCase { public static function assert_data_provider() : \Generator { - yield 'valid \DOMDocument' => [ - 'value' => new \DOMDocument, + yield 'valid HTMLDocument' => [ + 'value' => new HTMLDocument(''), 'exceptionClass' => null, ]; @@ -66,7 +67,6 @@ public static function cast_data_provider() : \Generator 'expected' => <<<'HTML'
1
- HTML, 'exceptionClass' => null, ]; @@ -75,7 +75,6 @@ public static function cast_data_provider() : \Generator 'value' => '
1
', 'expected' => <<<'HTML'
1
- HTML, 'exceptionClass' => null, ]; @@ -89,8 +88,8 @@ public static function cast_data_provider() : \Generator public static function is_valid_data_provider() : \Generator { - yield 'valid \DOMDocument' => [ - 'value' => new \DOMDocument(), + yield 'valid HTMLDocument' => [ + 'value' => new HTMLDocument(''), 'expected' => true, ]; @@ -117,7 +116,7 @@ public function test_assert(mixed $value, ?string $exceptionClass = null) : void $this->expectException($exceptionClass); type_html()->assert($value); } else { - self::assertInstanceOf(\DOMDocument::class, type_html()->assert($value)); + self::assertInstanceOf(HTMLDocument::class, type_html()->assert($value)); } } @@ -129,7 +128,7 @@ public function test_cast(mixed $value, mixed $expected, ?string $exceptionClass type_html()->cast($value); } else { $result = type_html()->cast($value); - self::assertSame($expected, $result->saveHtml()); + self::assertSame($expected, $result->toString()); } }