Merge branch '2.3' into 2.7

* 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
This commit is contained in:
Fabien Potencier 2016-01-20 07:45:12 +01:00
commit 6ec5537aed
6 changed files with 41 additions and 29 deletions

View File

@ -22,6 +22,8 @@ use Symfony\Component\Validator\Validation;
abstract class FrameworkExtensionTest extends TestCase
{
private static $containerCache = array();
abstract protected function loadFromFile(ContainerBuilder $container, $file);
public function testCsrfProtection()
@ -470,6 +472,10 @@ abstract class FrameworkExtensionTest extends TestCase
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);
@ -478,7 +484,7 @@ abstract class FrameworkExtensionTest extends TestCase
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();
return $container;
return self::$containerCache[$cacheKey] = $container;
}
protected function createContainerFromClosure($closure, $data = array())

View File

@ -38,6 +38,8 @@ class SplFileInfo extends \SplFileInfo
/**
* Returns the relative path.
*
* This path does not contain the file name.
*
* @return string the relative path
*/
public function getRelativePath()
@ -48,6 +50,8 @@ class SplFileInfo extends \SplFileInfo
/**
* Returns the relative path name.
*
* This path contains the file name.
*
* @return string the relative path name
*/
public function getRelativePathname()

View File

@ -17,11 +17,6 @@ use Symfony\Component\HttpFoundation\Request;
class RequestTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$this->testInitialize();
}
public function testInitialize()
{
$request = new Request();

View File

@ -240,9 +240,6 @@ class Process
* 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
@ -474,7 +471,11 @@ class Process
$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;
}
/**
@ -492,16 +493,13 @@ class Process
{
$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;
}
@ -536,7 +534,11 @@ class Process
$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;
}
/**
@ -555,16 +557,13 @@ class Process
{
$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;
}
@ -795,23 +794,33 @@ class Process
/**
* 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);
}
/**
@ -1393,8 +1402,8 @@ class Process
$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;

View File

@ -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
*/

View File

@ -59,8 +59,6 @@ class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerIn
*/
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');
}
}