8000 Merge branch '2.7' into 2.8 · symfony/symfony@bad218d · GitHub
[go: up one dir, main page]

Skip to content

Commit bad218d

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Process] Fix transient tests for incremental outputs
2 parents ab1fab2 + 114e5d6 commit bad218d

File tree

3 files changed

+27
-95
lines changed

3 files changed

+27
-95
lines changed

phpunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if ('phpdbg' === PHP_SAPI) {
2727
$PHP .= ' -qrr';
2828
}
2929

30-
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `where.exe composer.phar` : `which composer.phar`))
30+
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
3131
? $PHP.' '.ProcessUtils::escapeArgument($COMPOSER)
3232
: 'composer';
3333

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ public function testVeryLongHosts($host)
17871787
$request = Request::create('/');
17881788
$request->headers->set('host', $host);
17891789
$this->assertEquals($host, $request->getHost());
1790-
$this->assertLessThan(1, microtime(true) - $start);
1790+
$this->assertLessThan(3, microtime(true) - $start);
17911791
}
17921792

17931793
/**

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 25 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -331,27 +331,6 @@ public function testGetErrorOutput()
331331
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
332332
}
333333

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-
355334
public function testFlushErrorOutput()
356335
{
357336
$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()
361340
$this->assertEmpty($p->getErrorOutput());
362341
}
363342

364-
public function testGetEmptyIncrementalErrorOutput()
343+
/**
344+
* @dataProvider provideIncrementalOutput
345+
*/
346+
public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
365347
{
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__);
370349

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);
372354

373355
$p->start();
374356

375-
$shouldWrite = false;
357+
foreach (array('foo', 'bar') as $s) {
358+
while (false === strpos($p->$getOutput(), $s)) {
359+
usleep(1000);
360+
}
376361

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());
384364

385-
file_put_contents($lock, 'W');
386-
$shouldWrite = false;
387-
}
388-
}
389-
usleep(100);
365+
flock($h, LOCK_UN);
390366
}
391367

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+
);
393377
}
394378

395379
public function testGetOutput()
@@ -400,27 +384,6 @@ public function testGetOutput()
400384
$this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
401385
}
402386

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-
424387
public function testFlushOutput()
425388
{
426389
$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()
430393
$this->assertEmpty($p->getOutput());
431394
}
432395

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-
464396
public function testZeroAsOutput()
465397
{
466398
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
0