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()
4242     */ 
4343    public  function  isEmpty ()
4444    {
45-         return  $ this html  === '' ;
45+         return  ( $ this html  ??  '' )  === '' ;
4646    }
4747
4848    /** 
@@ -62,6 +62,6 @@ public function isNotEmpty()
6262     */ 
6363    public  function  __toString ()
6464    {
65-         return  $ this toHtml ();
65+         return  $ this toHtml () ??  '' ;
6666    }
6767}
Original file line number Diff line number Diff line change @@ -39,13 +39,20 @@ public function testToString()
3939        $ str'<h1>foo</h1> ' ;
4040        $ htmlnew  HtmlString ('<h1>foo</h1> ' );
4141        $ this assertEquals ($ strstring ) $ html
42+ 
43+         // Check if HtmlString gracefully handles a null value 
44+         $ htmlnew  HtmlString (null );
45+         $ this assertIsString ((string ) $ html
4246    }
4347
4448    public  function  testIsEmpty (): void 
4549    {
4650        // Check if HtmlString correctly identifies an empty string as empty 
4751        $ this assertTrue ((new  HtmlString ('' ))->isEmpty ());
4852
53+         // Check if HtmlString identifies a null value as empty 
54+         $ this assertTrue ((new  HtmlString (null ))->isEmpty ());
55+ 
4956        // HtmlString with whitespace should not be considered as empty 
5057        $ this assertFalse ((new  HtmlString ('    ' ))->isEmpty ());
5158
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments