File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,6 +83,12 @@ public function close(): void
8383
8484 public function write ( string $ text , Log \Data $ data ): void
8585 {
86+ // Only write if file handle is valid
87+ if ( !$ this ->_file || !is_resource ( $ this ->_file ) )
88+ {
89+ return ;
90+ }
91+
8692 fwrite ( $ this ->_file ,
8793 "$ text \r\n" );
8894 }
Original file line number Diff line number Diff line change @@ -42,4 +42,24 @@ public function testOpenFail()
4242
4343 $ this ->assertFalse ( $ Pass );
4444 }
45+
46+ public function testWriteWithInvalidFileHandle ()
47+ {
48+ $ File = new File ( new CSV () );
49+
50+ // Open should fail
51+ $ Pass = $ File ->open (
52+ [
53+ 'file_name ' => "//invalid//path/%DATE% "
54+ ]
55+ );
56+
57+ $ this ->assertFalse ( $ Pass );
58+
59+ // Write should not crash even with invalid file handle
60+ $ File ->log ( "Test message " , RunLevel::ERROR );
61+
62+ // Test passes if no exception is thrown
63+ $ this ->assertTrue ( true );
64+ }
4565}
You can’t perform that action at this time.
0 commit comments