Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  [Process] Remove a misleading comment
  Improve the phpdoc of SplFileInfo methods
  [Process] Use stream based storage to avoid memory issues
  Fixed the documentation of VoterInterface::supportsAttribute
  Remove useless duplicated tests
  [FrameworkBundle] Optimize framework extension tests
  Use is_subclass_of instead of Reflection when possible
  • Loading branch information
fabpot committed Jan 20, 2016
2 parents 20f0d60 + 6d8078f commit 6ec5537
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

abstract class FrameworkExtensionTest extends TestCase
{
private static $containerCache = array();

abstract protected function loadFromFile(ContainerBuilder $container, $file);

public function testCsrfProtection()
Expand Down Expand Up @@ -470,6 +472,10 @@ protected function createContainer(array $data = array())

protected function createContainerFromFile($file, $data = array())
{
$cacheKey = md5($file.serialize($data));
if (isset(self::$containerCache[$cacheKey])) {
return self::$containerCache[$cacheKey];
}
$container = $this->createContainer($data);
$container->registerExtension(new FrameworkExtension());
$this->loadFromFile($container, $file);
Expand All @@ -478,7 +484,7 @@ protected function createContainerFromFile($file, $data = array())
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();

return $container;
return self::$containerCache[$cacheKey] = $container;
}

protected function createContainerFromClosure($closure, $data = array())
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Finder/SplFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __construct($file, $relativePath, $relativePathname)
/**
* Returns the relative path.
*
* This path does not contain the file name.
*
* @return string the relative path
*/
public function getRelativePath()
Expand All @@ -48,6 +50,8 @@ public function getRelativePath()
/**
* Returns the relative path name.
*
* This path contains the file name.
*
* @return string the relative path name
*/
public function getRelativePathname()
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

class RequestTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$this->testInitialize();
}

public function testInitialize()
{
$request = new Request();
Expand Down
47 changes: 28 additions & 19 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ public function mustRun($callback = null)
* The callback receives the type of output (out or err) and some bytes from
* the output in real-time while writing the standard input to the process.
* It allows to have feedback from the independent process during execution.
* If there is no callback passed, the wait() method can be called
* with true as a second parameter then the callback will get all data occurred
* in (and since) the start call.
*
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
Expand Down Expand Up @@ -474,7 +471,11 @@ public function getOutput()

$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);

return $this->stdout;
if (false === $ret = stream_get_contents($this->stdout, -1, 0)) {
return '';
}

return $ret;
}

/**
Expand All @@ -492,16 +493,13 @@ public function getIncrementalOutput()
{
$this->requireProcessIsStarted(__FUNCTION__);

$data = $this->getOutput();

$latest = substr($data, $this->incrementalOutputOffset);
$latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
$this->incrementalOutputOffset = ftell($this->stdout);

if (false === $latest) {
return '';
}

$this->incrementalOutputOffset = strlen($data);

return $latest;
}

Expand Down Expand Up @@ -536,7 +534,11 @@ public function getErrorOutput()

$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);

return $this->stderr;
if (false === $ret = stream_get_contents($this->stderr, -1, 0)) {
return '';
}

return $ret;
}

/**
Expand All @@ -555,16 +557,13 @@ public function getIncrementalErrorOutput()
{
$this->requireProcessIsStarted(__FUNCTION__);

$data = $this->getErrorOutput();

$latest = substr($data, $this->incrementalErrorOutputOffset);
$latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
$this->incrementalErrorOutputOffset = ftell($this->stderr);

if (false === $latest) {
return '';
}

$this->incrementalErrorOutputOffset = strlen($data);

return $latest;
}

Expand Down Expand Up @@ -795,23 +794,33 @@ public function stop($timeout = 10, $signal = null)
/**
* Adds a line to the STDOUT stream.
*
* @internal
*
* @param string $line The line to append
*/
public function addOutput($line)
{
$this->lastOutputTime = microtime(true);
$this->stdout .= $line;

fseek($this->stdout, 0, SEEK_END);
fwrite($this->stdout, $line);
fseek($this->stdout, $this->incrementalOutputOffset);
}

/**
* Adds a line to the STDERR stream.
*
* @internal
*
* @param string $line The line to append
*/
public function addErrorOutput($line)
{
$this->lastOutputTime = microtime(true);
$this->stderr .= $line;

fseek($this->stderr, 0, SEEK_END);
fwrite($this->stderr, $line);
fseek($this->stderr, $this->incrementalErrorOutputOffset);
}

/**
Expand Down Expand Up @@ -1393,8 +1402,8 @@ private function resetProcessData()
$this->exitcode = null;
$this->fallbackStatus = array();
$this->processInformation = null;
$this->stdout = null;
$this->stderr = null;
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
$this->process = null;
$this->latestSignal = null;
$this->status = self::STATUS_READY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface VoterInterface
/**
* Checks if the voter supports the given attribute.
*
* @param string $attribute An attribute
* @param mixed $attribute An attribute (usually the attribute name string)
*
* @return bool true if this Voter supports the attribute, false otherwise
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public function supportsNormalization($data, $format = null)
*/
public function supportsDenormalization($data, $type, $format = null)
{
$class = new \ReflectionClass($type);

return $class->isSubclassOf('Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
}
}

0 comments on commit 6ec5537

Please sign in to comment.