File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public function toHtml()
42
42
*/
43
43
public function isEmpty ()
44
44
{
45
- return $ this ->html === '' ;
45
+ return ( $ this ->html ?? '' ) === '' ;
46
46
}
47
47
48
48
/**
@@ -62,6 +62,6 @@ public function isNotEmpty()
62
62
*/
63
63
public function __toString ()
64
64
{
65
- return $ this ->toHtml ();
65
+ return $ this ->toHtml () ?? '' ;
66
66
}
67
67
}
Original file line number Diff line number Diff line change @@ -39,13 +39,20 @@ public function testToString()
39
39
$ str = '<h1>foo</h1> ' ;
40
40
$ html = new HtmlString ('<h1>foo</h1> ' );
41
41
$ this ->assertEquals ($ str , (string ) $ html );
42
+
43
+ // Check if HtmlString gracefully handles a null value
44
+ $ html = new HtmlString (null );
45
+ $ this ->assertIsString ((string ) $ html );
42
46
}
43
47
44
48
public function testIsEmpty (): void
45
49
{
46
50
// Check if HtmlString correctly identifies an empty string as empty
47
51
$ this ->assertTrue ((new HtmlString ('' ))->isEmpty ());
48
52
53
+ // Check if HtmlString identifies a null value as empty
54
+ $ this ->assertTrue ((new HtmlString (null ))->isEmpty ());
55
+
49
56
// HtmlString with whitespace should not be considered as empty
50
57
$ this ->assertFalse ((new HtmlString (' ' ))->isEmpty ());
51
58
You can’t perform that action at this time.
0 commit comments