File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed
Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,22 @@ private function asArray()
3939
4040 public function asCsvLine (): string
4141 {
42- $ f = fopen ('php://memory ' , 'rb+ ' );
43- if (fputcsv ($ f , $ this ->asArray ()) === false ) {
44- throw new \RuntimeException ('Cannot format TimerEvent as CSV ' );
42+ $ csvStream = fopen ('php://memory ' , 'rb+ ' );
43+ if ($ csvStream === false ) {
44+ throw new \RuntimeException ('Could not open temporary stream ' );
45+ }
46+ try {
47+ if (fputcsv ($ csvStream , $ this ->asArray ()) === false ) {
48+ throw new \RuntimeException ('Could not format TimerEvent as CSV ' );
49+ }
50+ rewind ($ csvStream );
51+ $ line = stream_get_contents ($ csvStream );
52+ if ($ line === false ) {
53+ throw new \RuntimeException ('Could not read from temporary CSV stream ' );
54+ }
55+ } finally {
56+ fclose ($ csvStream );
4557 }
46- rewind ($ f );
47- $ line = stream_get_contents ($ f );
48- fclose ($ f );
4958 return rtrim ($ line );
5059 }
51- }
60+ }
Original file line number Diff line number Diff line change @@ -52,19 +52,22 @@ public function testTimerWithCsvResult()
5252 $ output ,
5353 'Test task should be executed. ' . "\n" .
5454 'Expected "Test Output" ' . "\n" .
55- 'Actual Output: ' . print_r ($ output ,true )
55+ 'Actual Output: ' . print_r ($ output , true )
5656 );
5757 $ this ->assertRegExp (<<<'REGEX'
5858{BEGIN,test,[\d.]+,[\d.]+
5959END,test,[\d.]+,[\d.]+}
6060REGEX
6161
62- , file_get_contents ($ csvFile ), 'CSV file should be written with timer results ' );
62+ , ( string ) file_get_contents ($ csvFile ), 'CSV file should be written with timer results ' );
6363 }
6464
6565 private function createTmpFile ()
6666 {
6767 $ fileName = tempnam (sys_get_temp_dir (), 'integer-net-deployer-timer ' );
68+ if (!$ fileName ) {
69+ throw new \RuntimeException ('Could not create temporary file ' );
70+ }
6871 $ this ->tmpFiles [] = $ fileName ;
6972 return $ fileName ;
7073 }
You can’t perform that action at this time.
0 commit comments