@@ -308,48 +308,60 @@ public function test_resetRows() {
308308 }
309309
310310 public function test_displayRow_ascii () {
311- $ mockFile = tempnam (sys_get_temp_dir (), 'temp ' );
312- $ resource = fopen ($ mockFile , 'wb ' );
313- \cli \Streams::setStream ('out ' , $ resource );
314-
315- $ table = new cli \Table ();
316- $ renderer = new cli \Table \Ascii ();
317- $ table ->setRenderer ( $ renderer );
318- $ table ->setHeaders ( array ( 'Name ' , 'Age ' ) );
319-
320- // Display a single row
321- $ table ->displayRow ( array ( 'Alice ' , '30 ' ) );
322-
323- $ output = file_get_contents ($ mockFile );
324- unlink ($ mockFile );
325-
326- // Should contain the row data
327- $ this ->assertStringContainsString ( 'Alice ' , $ output );
328- $ this ->assertStringContainsString ( '30 ' , $ output );
329-
330- // Should contain borders
331- $ this ->assertStringContainsString ( '| ' , $ output );
332- $ this ->assertStringContainsString ( '+ ' , $ output );
311+ $ mockFile = tempnam ( sys_get_temp_dir (), 'temp ' );
312+ $ resource = fopen ( $ mockFile , 'wb ' );
313+
314+ try {
315+ \cli \Streams::setStream ( 'out ' , $ resource );
316+
317+ $ table = new cli \Table ();
318+ $ renderer = new cli \Table \Ascii ();
319+ $ table ->setRenderer ( $ renderer );
320+ $ table ->setHeaders ( array ( 'Name ' , 'Age ' ) );
321+
322+ // Display a single row
323+ $ table ->displayRow ( array ( 'Alice ' , '30 ' ) );
324+
325+ $ output = file_get_contents ( $ mockFile );
326+
327+ // Should contain the row data
328+ $ this ->assertStringContainsString ( 'Alice ' , $ output );
329+ $ this ->assertStringContainsString ( '30 ' , $ output );
330+
331+ // Should contain borders
332+ $ this ->assertStringContainsString ( '| ' , $ output );
333+ $ this ->assertStringContainsString ( '+ ' , $ output );
334+ } finally {
335+ if ( $ mockFile && file_exists ( $ mockFile ) ) {
336+ unlink ( $ mockFile );
337+ }
338+ }
333339 }
334340
335341 public function test_displayRow_tabular () {
336- $ mockFile = tempnam (sys_get_temp_dir (), 'temp ' );
337- $ resource = fopen ($ mockFile , 'wb ' );
338- \cli \Streams::setStream ('out ' , $ resource );
339-
340- $ table = new cli \Table ();
341- $ renderer = new cli \Table \Tabular ();
342- $ table ->setRenderer ( $ renderer );
343- $ table ->setHeaders ( array ( 'Name ' , 'Age ' ) );
344-
345- // Display a single row
346- $ table ->displayRow ( array ( 'Alice ' , '30 ' ) );
347-
348- $ output = file_get_contents ($ mockFile );
349- unlink ($ mockFile );
350-
351- // Should contain the row data with tabs
352- $ this ->assertStringContainsString ( 'Alice ' , $ output );
353- $ this ->assertStringContainsString ( '30 ' , $ output );
342+ $ mockFile = tempnam ( sys_get_temp_dir (), 'temp ' );
343+ $ resource = fopen ( $ mockFile , 'wb ' );
344+
345+ try {
346+ \cli \Streams::setStream ( 'out ' , $ resource );
347+
348+ $ table = new cli \Table ();
349+ $ renderer = new cli \Table \Tabular ();
350+ $ table ->setRenderer ( $ renderer );
351+ $ table ->setHeaders ( array ( 'Name ' , 'Age ' ) );
352+
353+ // Display a single row
354+ $ table ->displayRow ( array ( 'Alice ' , '30 ' ) );
355+
356+ $ output = file_get_contents ( $ mockFile );
357+
358+ // Should contain the row data with tabs
359+ $ this ->assertStringContainsString ( 'Alice ' , $ output );
360+ $ this ->assertStringContainsString ( '30 ' , $ output );
361+ } finally {
362+ if ( $ mockFile && file_exists ( $ mockFile ) ) {
363+ unlink ( $ mockFile );
364+ }
365+ }
354366 }
355367}
0 commit comments