@@ -331,27 +331,6 @@ public function testGetErrorOutput()
331
331
$ this ->assertEquals (3 , preg_match_all ('/ERROR/ ' , $ p ->getErrorOutput (), $ matches ));
332
332
}
333
333
334
- public function testGetIncrementalErrorOutput ()
335
- {
336
- // use a lock file to toggle between writing ("W") and reading ("R") the
337
- // error stream
338
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'
10000
Lock ' );
339
- file_put_contents ($ lock , 'W ' );
340
-
341
- $ 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); } ' )));
342
-
343
- $ p ->start ();
344
- while ($ p ->isRunning ()) {
345
- if ('R ' === file_get_contents ($ lock )) {
346
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/ERROR/ ' , $ p ->getIncrementalErrorOutput (), $ matches ));
347
- file_put_contents ($ lock , 'W ' );
348
- }
349
- usleep (100 );
350
- }
351
-
352
- unlink ($ lock );
353
- }
354
-
355
334
public function testFlushErrorOutput ()
356
335
{
357
336
$ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 0; while ($n < 3) { file_put_contents( \'php://stderr \', \'ERROR \'); $n++; } ' )));
@@ -361,35 +340,40 @@ public function testFlushErrorOutput()
361
340
$ this ->assertEmpty ($ p ->getErrorOutput ());
362
341
}
363
342
364
- public function testGetEmptyIncrementalErrorOutput ()
343
+ /**
344
+ * @dataProvider provideIncrementalOutput
345
+ */
346
+ public function testIncrementalOutput ($ getOutput , $ getIncrementalOutput , $ uri )
365
347
{
366
- // use a lock file to toggle between writing ("W") and reading ("R") the
367
- // output stream
368
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
369
- file_put_contents ($ lock , 'W ' );
348
+ $ lock = tempnam (sys_get_temp_dir (), __FUNCTION__ );
370
349
371
- $ 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); } ' )));
350
+ $ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('file_put_contents($s = \'' .$ uri .'\', \'foo \'); flock(fopen( ' .var_export ($ lock , true ).', \'r \'), LOCK_EX); file_put_contents($s, \'bar \'); ' )));
351
+
352
+ $ h = fopen ($ lock , 'w ' );
353
+ flock ($ h , LOCK_EX );
372
354
373
355
$ p ->start ();
374
356
375
- $ shouldWrite = false ;
357
+ foreach (array ('foo ' , 'bar ' ) as $ s ) {
358
+ while (false === strpos ($ p ->$ getOutput (), $ s )) {
359
+ usleep (1000 );
360
+ }
376
361
377
- while ($ p ->isRunning ()) {
378
- if ('R ' === file_get_contents ($ lock )) {
379
- if (!$ shouldWrite ) {
380
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/ERROR/ ' , $ p ->getIncrementalOutput (), $ matches ));
381
- $ shouldWrite = true ;
382
- } else {
383
- $ this ->assertSame ('' , $ p ->getIncrementalOutput ());
362
+ $ this ->assertSame ($ s , $ p ->$ getIncrementalOutput ());
363
+ $ this ->assertSame ('' , $ p ->$ getIncrementalOutput ());
384
364
385
- file_put_contents ($ lock , 'W ' );
386
- $ shouldWrite = false ;
387
- }
388
- }
389
- usleep (100 );
365
+ flock ($ h , LOCK_UN );
390
366
}
391
367
392
- unlink ($ lock );
368
+ fclose ($ h );
369
+ }
370
+
371
+ public function provideIncrementalOutput ()
372
+ {
373
+ return array (
374
+ array ('getOutput ' , 'getIncrementalOutput ' , 'php://stdout ' ),
375
+ array ('getErrorOutput ' , 'getIncrementalErrorOutput ' , 'php://stderr ' ),
376
+ );
393
377
}
394
378
395
379
public function testGetOutput ()
@@ -400,27 +384,6 @@ public function testGetOutput()
400
384
$ this ->assertEquals (3 , preg_match_all ('/foo/ ' , $ p ->getOutput (), $ matches ));
401
385
}
402
386
403
- public function testGetIncrementalOutput ()
404
- {
405
- // use a lock file to toggle between writing ("W") and reading ("R") the
406
- // output stream
407
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
408
- file_put_contents ($ lock , 'W ' );
409
-
410
- $ 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); } ' )));
411
-
412
- $ p ->start ();
413
- while ($ p ->isRunning ()) {
414
- if ('R ' === file_get_contents ($ lock )) {
415
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/foo/ ' , $ p ->getIncrementalOutput (), $ matches ));
416
- file_put_contents ($ lock , 'W ' );
417
- }
418
- usleep (100 );
419
- }
420
-
421
- unlink ($ lock );
422
- }
423
-
424
387
public function testFlushOutput ()
425
388
{
426
389
$ p = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n=0;while ($n<3) {echo \' foo \';$n++;} ' )));
@@ -430,37 +393,6 @@ public function testFlushOutput()
430
393
$ this ->assertEmpty ($ p ->getOutput ());
431
394
}
432
395
433
- public function testGetEmptyIncrementalOutput ()
434
- {
435
- // use a lock file to toggle between writing ("W") and reading ("R") the
436
- // output stream
437
- $ lock = tempnam (sys_get_temp_dir (), get_class ($ this ).'Lock ' );
438
- file_put_contents ($ lock , 'W ' );
439
-
440
- $ 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); } ' )));
441
-
442
- $ p ->start ();
443
-
444
- $ shouldWrite = false ;
445
-
446
- while ($ p ->isRunning ()) {
447
- if ('R ' === file_get_contents ($ lock )) {
448
- if (!$ shouldWrite ) {
449
- $ this ->assertLessThanOrEqual (1 , preg_match_all ('/foo/ ' , $ p ->getIncrementalOutput (), $ matches ));
450
- $ shouldWrite = true ;
451
- } else {
452
- $ this ->assertSame ('' , $ p ->getIncrementalOutput ());
453
-
454
- file_put_contents ($ lock , 'W ' );
455
- $ shouldWrite = false ;
456
- }
457
- }
458
- usleep (100 );
459
- }
460
-
461
- unlink ($ lock );
462
- }
463
-
464
396
public function testZeroAsOutput ()
465
397
{
466
398
if ('\\' === DIRECTORY_SEPARATOR ) {
0 commit comments