@@ -290,56 +290,44 @@ public function testGetErrorOutput()
290
290
$ this ->assertEquals (3 , preg_match_all ('/ERROR/ ' , $ p ->getErrorOutput (), $ matches ));
291
291
}
292
292
293
- public function testGetIncrementalErrorOutput ()
293
+ /**
294
+ * @dataProvider provideIncrementalOutput
295
+ */
296
+ public function testIncrementalOutput ($ getOutput , $ getIncrementalOutput , $ uri )
294
297
{
295
- // use a lock file to toggle between writing ("W") and reading ("R") the
296
- // error stream
297
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
298
- file_put_contents ($ lock , 'W ' );
298
+ $ lock = tempnam (sys_get_temp_dir (), __FUNCTION__ );
299
+
300
+ $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('file_put_contents($s = \'' .$ uri .'\', $s); flock(fopen( ' .var_export ($ lock , true ).', \'r \'), LOCK_EX); file_put_contents($s, \'foo \'); ' )));
299
301
300
- $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 0; while ($n < 3) { if ( \'W \' === file_get_contents( ' .var_export ($ lock , true ).')) { file_put_contents( \'php://stderr \', \'ERROR \'); $n++; file_put_contents( ' .var_export ($ lock , true ).', \'R \'); } usleep(100); } ' )));
302
+ $ h = fopen ($ lock , 'w ' );
303
+ flock ($ h , LOCK_EX );
301
304
302
305
$ p ->start ();
303
- while ($ p ->isRunning ()) {
304
- if ('R ' === file_get_contents ($ lock )) {
305
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/ERROR/ ' , $ p ->getIncrementalErrorOutput (), $ matches ));
306
- file_put_contents ($ lock , 'W ' );
307
- }
308
- usleep (100 );
306
+ while (false === strpos ($ p ->$ getOutput (), $ uri )) {
307
+ usleep (1000 );
309
308
}
310
309
311
- unlink ( $ lock );
312
- }
310
+ $ this -> assertSame ( $ uri , $ p -> $ getIncrementalOutput () );
311
+ $ this -> assertSame ( '' , $ p -> $ getIncrementalOutput ());
313
312
314
- public function testGetEmptyIncrementalErrorOutput ()
315
- {
316
- // use a lock file to toggle between writing ("W") and reading ("R") the
317
- // output stream
318
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
319
- file_put_contents ($ lock , 'W ' );
320
-
321
- $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 0; while ($n < 3) { if ( \'W \' === file_get_contents( ' .var_export ($ lock , true ).')) { file_put_contents( \'php://stderr \', \'ERROR \'); $n++; file_put_contents( ' .var_export ($ lock , true ).', \'R \'); } usleep(100); } ' )));
313
+ flock ($ h , LOCK_UN );
322
314
323
- $ p ->start ();
324
-
325
- $ shouldWrite = false ;
315
+ while ( false === strpos ( $ p ->$ getOutput (), ' foo ' )) {
316
+ usleep ( 1000 );
317
+ }
326
318
327
- while ($ p ->isRunning ()) {
328
- if ('R ' === file_get_contents ($ lock )) {
329
- if (!$ shouldWrite ) {
330
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/ERROR/ ' , $ p ->getIncrementalOutput (), $ matches ));
331
- $ shouldWrite = true ;
332
- } else {
333
- $ this ->assertSame ('' , $ p ->getIncrementalOutput ());
319
+ $ this ->assertSame ('foo ' , $ p ->$ getIncrementalOutput ());
320
+ $ this ->assertSame ('' , $ p ->$ getIncrementalOutput ());
334
321
335
- file_put_contents ($ lock , 'W ' );
336
- $ shouldWrite = false ;
337
- }
338
- }
339
- usleep (100 );
340
- }
322
+ fclose ($ h );
323
+ }
341
324
342
- unlink ($ lock );
325
+ public function provideIncrementalOutput ()
326
+ {
327
+ return array (
328
+ array ('getOutput ' , 'getIncrementalOutput ' , 'php://stdout ' ),
329
+ array ('getErrorOutput ' , 'getIncrementalErrorOutput ' , 'php://stderr ' ),
330
+ );
343
331
}
344
332
345
333
public function testGetOutput ()
@@ -350,58 +338,6 @@ public function testGetOutput()
350
338
$ this ->assertEquals (3 , preg_match_all ('/foo/ ' , $ p ->getOutput (), $ matches ));
351
339
}
352
340
353
- public function testGetIncrementalOutput ()
354
- {
355
- // use a lock file to toggle between writing ("W") and reading ("R") the
356
- // output stream
357
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
358
- file_put_contents ($ lock , 'W ' );
359
-
360
- $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 0; while ($n < 3) { if ( \'W \' === file_get_contents( ' .var_export ($ lock , true ).')) { echo \' foo \'; $n++; file_put_contents( ' .var_export ($ lock , true ).', \'R \'); } usleep(100); } ' )));
361
-
362
- $ p ->start ();
363
- while ($ p ->isRunning ()) {
364
- if ('R ' === file_get_contents ($ lock )) {
365
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/foo/ ' , $ p ->getIncrementalOutput (), $ matches ));
366
- file_put_contents ($ lock , 'W ' );
367
- }
368
- usleep (100 );
369
- }
370
-
371
- unlink ($ lock );
372
- }
373
-
374
- public function testGetEmptyIncrementalOutput ()
375
- {
376
- // use a lock file to toggle between writing ("W") and reading ("R") the
377
- // output stream
378
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
379
- file_put_contents ($ lock , 'W ' );
380
-
381
- $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 0; while ($n < 3) { if ( \'W \' === file_get_contents( ' .var_export ($ lock , true ).')) { echo \' foo \'; $n++; file_put_contents( ' .var_export ($ lock , true ).', \'R \'); } usleep(100); } ' )));
382
-
383
- $ p ->start ();
384
-
385
- $ shouldWrite = false ;
386
-
387
- while ($ p ->isRunning ()) {
388
- if ('R ' === file_get_contents ($ lock )) {
389
- if (!$ shouldWrite ) {
390
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/foo/ ' , $ p ->getIncrementalOutput (), $ matches ));
391
- $ shouldWrite = true ;
392
- } else {
393
- $ this ->assertSame ('' , $ p ->getIncrementalOutput ());
394
-
395
- file_put_contents ($ lock , 'W ' );
396
- $ shouldWrite = false ;
397
- }
398
- }
399
- usleep (100 );
400
- }
401
-
402
- unlink ($ lock );
403
- }
404
-
405
341
public function testZeroAsOutput ()
406
342
{
407
343
if ('\\' === DIRECTORY_SEPARATOR ) {
0 commit comments