Merge branch '2.8' into 3.2

* 2.8:
  Revert "bug #21436 [DependencyInjection] check for circular refs caused by method calls (xabbuh)"
  Static code analysis with Php Inspections (EA Extended)
  [VarDumper] Added missing persistent stream cast
This commit is contained in:
Fabien Potencier 2017-02-16 14:46:52 -08:00
commit ea12123bcf
21 changed files with 39 additions and 82 deletions

View File

@ -63,9 +63,7 @@ class HttpKernelExtensionTest extends \PHPUnit_Framework_TestCase
$context->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
$renderer = new FragmentHandler($context, array($strategy), false);
return $renderer;
return new FragmentHandler($context, array($strategy), false);
}
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')

View File

@ -133,7 +133,7 @@ class CodeHelper extends Helper
$code = @highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
$content = preg_split('#<br />#', $code);
$content = explode('<br />', $code);
$lines = array();
for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; ++$i) {

View File

@ -46,4 +46,4 @@ EOF
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg2', intval(4.5), [], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), [], 'not_messages'); ?>

View File

@ -77,17 +77,4 @@ class SimpleFormFactory extends FormLoginFactory
return $listenerId;
}
protected function createEntryPoint($container, $id, $config, $defaultEntryPoint)
{
$entryPointId = 'security.authentication.form_entry_point.'.$id;
$container
->setDefinition($entryPointId, new DefinitionDecorator('security.authentication.form_entry_point'))
->addArgument(new Reference('security.http_utils'))
->addArgument($config['login_path'])
->addArgument($config['use_forward'])
;
return $entryPointId;
}
}

View File

@ -65,7 +65,6 @@ class PassConfig
new RemoveUnusedDefinitionsPass(),
)),
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new CheckCircularReferencesPass(),
));
}

View File

@ -113,30 +113,4 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($container->hasDefinition('b'));
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testCircularReferencesCausedByMethodCallsAreDetectedDuringCompilation()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container
->register('foobar', '\stdClass')
->addArgument(new Reference('foo'))
;
$container
->register('foo', '\stdClass')
->addArgument(new Reference('bar'))
;
$container
->register('foo', '\stdClass')
->addMethodCall('addFoobar', array(new Reference('foobar')))
;
$container->compile();
}
}

View File

@ -36,7 +36,7 @@ class CrossCheckTest extends \PHPUnit_Framework_TestCase
$tmp = tempnam(sys_get_temp_dir(), 'sf');
file_put_contents($tmp, file_get_contents(self::$fixturesPath.'/'.$type.'/'.$fixture));
copy(self::$fixturesPath.'/'.$type.'/'.$fixture, $tmp);
$container1 = new ContainerBuilder();
$loader1 = new $loaderClass($container1, new FileLocator());

View File

@ -63,6 +63,7 @@ $container
;
$container
->register('baz', 'Baz')
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
;
$container
->register('request', 'Request')

View File

@ -41,5 +41,6 @@ digraph sc {
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
node_inlined -> node_baz [label="setBaz()" style="dashed"];
node_baz -> node_foo_with_inline [label="setFoo()" style="dashed"];
node_configurator_service -> node_baz [label="setFoo()" style="dashed"];
}

View File

@ -91,7 +91,11 @@ class ProjectServiceContainer extends Container
*/
protected function getBazService()
{
return $this->services['baz'] = new \Baz();
$this->services['baz'] = $instance = new \Baz();
$instance->setFoo($this->get('foo_with_inline'));
return $instance;
}
/**

View File

@ -97,7 +97,11 @@ class ProjectServiceContainer extends Container
*/
protected function getBazService()
{
return $this->services['baz'] = new \Baz();
$this->services['baz'] = $instance = new \Baz();
$instance->setFoo($this->get('foo_with_inline'));
return $instance;
}
/**
@ -268,11 +272,12 @@ class ProjectServiceContainer extends Container
protected function getFooWithInlineService()
{
$a = new \Bar();
$a->pub = 'pub';
$a->setBaz($this->get('baz'));
$this->services['foo_with_inline'] = $instance = new \Foo();
$a->pub = 'pub';
$a->setBaz($this->get('baz'));
$instance->setBar($a);
return $instance;

View File

@ -70,7 +70,11 @@
<argument type="service" id="baz"/>
</call>
</service>
<service id="baz" class="Baz"/>
<service id="baz" class="Baz">
<call method="setFoo">
<argument type="service" id="foo_with_inline"/>
</call>
</service>
<service id="request" class="Request" synthetic="true"/>
<service id="configurator_service" class="ConfClass" public="false">
<call method="setFoo">

View File

@ -52,6 +52,8 @@ services:
baz:
class: Baz
calls:
- [setFoo, ['@foo_with_inline']]
request:
class: Request

View File

@ -164,7 +164,7 @@ class BinaryFileResponse extends Response
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
$encoding = mb_detect_encoding($filename, null, true);
for ($i = 0; $i < mb_strlen($filename, $encoding); ++$i) {
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
$char = mb_substr($filename, $i, 1, $encoding);
if ('%' === $char || ord($char) < 32 || ord($char) > 126) {

View File

@ -106,7 +106,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
if (phpversion('mongodb')) {
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$gte']);
$this->assertGreaterThanOrEqual(round(intval((string) $criteria[$this->options['expiry_field']]['$gte']) / 1000), $testTimeout);
$this->assertGreaterThanOrEqual(round(((int) $criteria[$this->options['expiry_field']]['$gte']) / 1000), $testTimeout);
} else {
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$gte']);
$this->assertGreaterThanOrEqual($criteria[$this->options['expiry_field']]['$gte']->sec, $testTimeout);
@ -164,7 +164,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]);
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]);
$this->assertGreaterThanOrEqual($expectedExpiry, round(intval((string) $data[$this->options['expiry_field']]) / 1000));
$this->assertGreaterThanOrEqual($expectedExpiry, round(((int) $data[$this->options['expiry_field']]) / 1000));
} else {
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
@ -287,7 +287,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
->will($this->returnCallback(function ($criteria) {
if (phpversion('mongodb')) {
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$lt']);
$this->assertGreaterThanOrEqual(time() - 1, round(intval((string) $criteria[$this->options['expiry_field']]['$lt']) / 1000));
$this->assertGreaterThanOrEqual(time() - 1, round(((int) $criteria[$this->options['expiry_field']]['$lt']) / 1000));
} else {
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$lt']);
$this->assertGreaterThanOrEqual(time() - 1, $criteria[$this->options['expiry_field']]['$lt']->sec);

View File

@ -25,6 +25,9 @@ use Symfony\Component\HttpFoundation\Response;
* Client simulates a browser and makes requests to a Kernel object.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method Request|null getRequest() A Request instance
* @method Response|null getResponse() A Response instance
*/
class Client extends BaseClient
{
@ -47,26 +50,6 @@ class Client extends BaseClient
parent::__construct($server, $history, $cookieJar);
}
/**
* {@inheritdoc}
*
* @return Request|null A Request instance
*/
public function getRequest()
{
return parent::getRequest();
}
/**
* {@inheritdoc}
*
* @return Response|null A Response instance
*/
public function getResponse()
{
return parent::getResponse();
}
/**
* Makes a request.
*

View File

@ -37,7 +37,7 @@ class ValueExporter
if (is_object($value)) {
if ($value instanceof \DateTimeInterface) {
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ATOM));
}
return sprintf('Object(%s)', get_class($value));

View File

@ -31,13 +31,13 @@ class ValueExporterTest extends \PHPUnit_Framework_TestCase
public function testDateTime()
{
$dateTime = new \DateTime('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
}
public function testDateTimeImmutable()
{
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+00:00', $this->valueExporter->exportValue($dateTime));
}
public function testIncompleteClass()

View File

@ -86,8 +86,6 @@ class DataCollectorTranslatorTest extends \PHPUnit_Framework_TestCase
$translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
$translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru');
$collector = new DataCollectorTranslator($translator);
return $collector;
return new DataCollectorTranslator($translator);
}
}

View File

@ -118,6 +118,7 @@ abstract class AbstractCloner implements ClonerInterface
':pgsql result' => 'Symfony\Component\VarDumper\Caster\PgSqlCaster::castResult',
':process' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castProcess',
':stream' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castStream',
':persistent stream' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castStream',
':stream-context' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castStreamContext',
':xml' => 'Symfony\Component\VarDumper\Caster\XmlResourceCaster::castXml',
);

View File

@ -684,7 +684,7 @@ class Parser
$previousLineIndented = false;
$previousLineBlank = false;
for ($i = 0; $i < count($blockLines); ++$i) {
for ($i = 0, $blockLinesCount = count($blockLines); $i < $blockLinesCount; ++$i) {
if ('' === $blockLines[$i]) {
$text .= "\n";
$previousLineIndented = false;