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:
commit
6ec5537aed
@ -22,6 +22,8 @@ use Symfony\Component\Validator\Validation;
|
|||||||
|
|
||||||
abstract class FrameworkExtensionTest extends TestCase
|
abstract class FrameworkExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private static $containerCache = array();
|
||||||
|
|
||||||
abstract protected function loadFromFile(ContainerBuilder $container, $file);
|
abstract protected function loadFromFile(ContainerBuilder $container, $file);
|
||||||
|
|
||||||
public function testCsrfProtection()
|
public function testCsrfProtection()
|
||||||
@ -470,6 +472,10 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
|
|
||||||
protected function createContainerFromFile($file, $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 = $this->createContainer($data);
|
||||||
$container->registerExtension(new FrameworkExtension());
|
$container->registerExtension(new FrameworkExtension());
|
||||||
$this->loadFromFile($container, $file);
|
$this->loadFromFile($container, $file);
|
||||||
@ -478,7 +484,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$container->getCompilerPassConfig()->setRemovingPasses(array());
|
$container->getCompilerPassConfig()->setRemovingPasses(array());
|
||||||
$container->compile();
|
$container->compile();
|
||||||
|
|
||||||
return $container;
|
return self::$containerCache[$cacheKey] = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createContainerFromClosure($closure, $data = array())
|
protected function createContainerFromClosure($closure, $data = array())
|
||||||
|
@ -38,6 +38,8 @@ class SplFileInfo extends \SplFileInfo
|
|||||||
/**
|
/**
|
||||||
* Returns the relative path.
|
* Returns the relative path.
|
||||||
*
|
*
|
||||||
|
* This path does not contain the file name.
|
||||||
|
*
|
||||||
* @return string the relative path
|
* @return string the relative path
|
||||||
*/
|
*/
|
||||||
public function getRelativePath()
|
public function getRelativePath()
|
||||||
@ -48,6 +50,8 @@ class SplFileInfo extends \SplFileInfo
|
|||||||
/**
|
/**
|
||||||
* Returns the relative path name.
|
* Returns the relative path name.
|
||||||
*
|
*
|
||||||
|
* This path contains the file name.
|
||||||
|
*
|
||||||
* @return string the relative path name
|
* @return string the relative path name
|
||||||
*/
|
*/
|
||||||
public function getRelativePathname()
|
public function getRelativePathname()
|
||||||
|
@ -17,11 +17,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
|
|
||||||
class RequestTest extends \PHPUnit_Framework_TestCase
|
class RequestTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testConstructor()
|
|
||||||
{
|
|
||||||
$this->testInitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInitialize()
|
public function testInitialize()
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
@ -240,9 +240,6 @@ class Process
|
|||||||
* The callback receives the type of output (out or err) and some bytes from
|
* 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.
|
* the output in real-time while writing the standard input to the process.
|
||||||
* It allows to have feedback from the independent process during execution.
|
* 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
|
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||||
* output available on STDOUT or STDERR
|
* output available on STDOUT or STDERR
|
||||||
@ -474,7 +471,11 @@ class Process
|
|||||||
|
|
||||||
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
$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__);
|
$this->requireProcessIsStarted(__FUNCTION__);
|
||||||
|
|
||||||
$data = $this->getOutput();
|
$latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
|
||||||
|
$this->incrementalOutputOffset = ftell($this->stdout);
|
||||||
$latest = substr($data, $this->incrementalOutputOffset);
|
|
||||||
|
|
||||||
if (false === $latest) {
|
if (false === $latest) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->incrementalOutputOffset = strlen($data);
|
|
||||||
|
|
||||||
return $latest;
|
return $latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +534,11 @@ class Process
|
|||||||
|
|
||||||
$this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
$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__);
|
$this->requireProcessIsStarted(__FUNCTION__);
|
||||||
|
|
||||||
$data = $this->getErrorOutput();
|
$latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
|
||||||
|
$this->incrementalErrorOutputOffset = ftell($this->stderr);
|
||||||
$latest = substr($data, $this->incrementalErrorOutputOffset);
|
|
||||||
|
|
||||||
if (false === $latest) {
|
if (false === $latest) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->incrementalErrorOutputOffset = strlen($data);
|
|
||||||
|
|
||||||
return $latest;
|
return $latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,23 +794,33 @@ class Process
|
|||||||
/**
|
/**
|
||||||
* Adds a line to the STDOUT stream.
|
* Adds a line to the STDOUT stream.
|
||||||
*
|
*
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
* @param string $line The line to append
|
* @param string $line The line to append
|
||||||
*/
|
*/
|
||||||
public function addOutput($line)
|
public function addOutput($line)
|
||||||
{
|
{
|
||||||
$this->lastOutputTime = microtime(true);
|
$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.
|
* Adds a line to the STDERR stream.
|
||||||
*
|
*
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
* @param string $line The line to append
|
* @param string $line The line to append
|
||||||
*/
|
*/
|
||||||
public function addErrorOutput($line)
|
public function addErrorOutput($line)
|
||||||
{
|
{
|
||||||
$this->lastOutputTime = microtime(true);
|
$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->exitcode = null;
|
||||||
$this->fallbackStatus = array();
|
$this->fallbackStatus = array();
|
||||||
$this->processInformation = null;
|
$this->processInformation = null;
|
||||||
$this->stdout = null;
|
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
|
||||||
$this->stderr = null;
|
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
|
||||||
$this->process = null;
|
$this->process = null;
|
||||||
$this->latestSignal = null;
|
$this->latestSignal = null;
|
||||||
$this->status = self::STATUS_READY;
|
$this->status = self::STATUS_READY;
|
||||||
|
@ -27,7 +27,7 @@ interface VoterInterface
|
|||||||
/**
|
/**
|
||||||
* Checks if the voter supports the given attribute.
|
* 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
|
* @return bool true if this Voter supports the attribute, false otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -59,8 +59,6 @@ class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerIn
|
|||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null)
|
public function supportsDenormalization($data, $type, $format = null)
|
||||||
{
|
{
|
||||||
$class = new \ReflectionClass($type);
|
return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
|
||||||
|
|
||||||
return $class->isSubclassOf('Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user