Merge branch '2.3' into 2.4

* 2.3:
  [Config] made a condition more explicit
  convertDomElementToArray should handle zero values
  prefixed http:// to url output on server:run command in order to make it clickable
  Fixed data in pipe being truncated if not read before process termination
This commit is contained in:
Fabien Potencier 2014-03-13 06:40:32 +01:00
commit 1d19ca2395
5 changed files with 35 additions and 4 deletions

View File

@ -90,7 +90,7 @@ EOF
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
;
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
$builder->setWorkingDirectory($input->getOption('docroot'));

View File

@ -80,6 +80,7 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
array(array('foo' => null), '<foo />'),
array(array('foo' => 'bar'), '<foo>bar</foo>'),
array(array('foo' => array('foo' => 'bar')), '<foo foo="bar"/>'),
array(array('foo' => array('foo' => 0)), '<foo><foo>0</foo></foo>'),
array(array('foo' => array('foo' => 'bar')), '<foo><foo>bar</foo></foo>'),
array(array('foo' => array('foo' => 'bar', 'value' => 'text')), '<foo foo="bar">text</foo>'),
array(array('foo' => array('attr' => 'bar', 'foo' => 'text')), '<foo attr="bar"><foo>text</foo></foo>'),

View File

@ -132,7 +132,7 @@ class XmlUtils
$nodeValue = false;
foreach ($element->childNodes as $node) {
if ($node instanceof \DOMText) {
if (trim($node->nodeValue)) {
if ('' !== trim($node->nodeValue)) {
$nodeValue = trim($node->nodeValue);
$empty = false;
}

View File

@ -289,9 +289,13 @@ class ProcessPipes
foreach ($r as $pipe) {
$type = array_search($pipe, $this->pipes);
$data = fread($pipe, 8192);
if (strlen($data) > 0) {
$data = '';
while ($dataread = fread($pipe, 8192)) {
$data .= $dataread;
}
if ($data) {
$read[$type] = $data;
}

View File

@ -81,6 +81,32 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$this->assertLessThan(1.8, $duration);
}
public function testAllOutputIsActuallyReadOnTermination()
{
// this code will result in a maximum of 2 reads of 8192 bytes by calling
// start() and isRunning(). by the time getOutput() is called the process
// has terminated so the internal pipes array is already empty. normally
// the call to start() will not read any data as the process will not have
// generated output, but this is non-deterministic so we must count it as
// a possibility. therefore we need 2 * 8192 plus another byte which will
// never be read.
$expectedOutputSize = 16385;
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
$p->start();
usleep(250000);
if ($p->isRunning()) {
$this->fail('Process execution did not complete in the required time frame');
}
$o = $p->getOutput();
$this->assertEquals($expectedOutputSize, strlen($o));
}
public function testCallbacksAreExecutedWithStart()
{
$data = '';