From 23431e99d691ac6669439a21234e49d3d94f10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 10 Dec 2015 11:46:31 +0100 Subject: [PATCH 01/16] [FrameworkBundle] Compute the kernel root hash only one time --- .../FrameworkExtension.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 08a7b12de4..855fcf8ab7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -38,6 +38,11 @@ class FrameworkExtension extends Extension private $translationConfigEnabled = false; private $sessionConfigEnabled = false; + /** + * @var string|null + */ + private $kernelRootHash; + /** * Responds to the app.config configuration parameter. * @@ -777,7 +782,7 @@ class FrameworkExtension extends Extension if (isset($config['cache'])) { $container->setParameter( 'validator.mapping.cache.prefix', - 'validator_'.hash('sha256', $container->getParameter('kernel.root_dir')) + 'validator_'.$this->getKernelRootHash($container) ); $validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache']))); @@ -959,7 +964,7 @@ class FrameworkExtension extends Extension if (isset($config['cache']) && $config['cache']) { $container->setParameter( 'serializer.mapping.cache.prefix', - 'serializer_'.hash('sha256', $container->getParameter('kernel.root_dir')) + 'serializer_'.$this->getKernelRootHash($container) ); $container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument( @@ -968,6 +973,22 @@ class FrameworkExtension extends Extension } } + /** + * Gets a hash of the kernel root directory. + * + * @param ContainerBuilder $container + * + * @return string + */ + private function getKernelRootHash(ContainerBuilder $container) + { + if (!$this->kernelRootHash) { + $this->kernelRootHash = hash('sha256', $container->getParameter('kernel.root_dir')); + } + + return $this->kernelRootHash; + } + /** * Returns the base path for the XSD files. * From 369b2d4876501ee5ff7043e42a60d8c4fba3dd17 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Tue, 8 Dec 2015 14:36:25 +0000 Subject: [PATCH 02/16] [Translation][Writer] avoid calling setBackup if the dumper is not an instance of FileDumper. --- .../Tests/Writer/TranslationWriterTest.php | 47 +++++++++++++++++++ .../Translation/Writer/TranslationWriter.php | 4 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php diff --git a/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php b/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php new file mode 100644 index 0000000000..501ced82e3 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Writer; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Writer\TranslationWriter; + +class TranslationWriterTest extends \PHPUnit_Framework_TestCase +{ + public function testWriteTranslations() + { + $dumper = $this->getMock('Symfony\Component\Translation\Dumper\DumperInterface'); + $dumper + ->expects($this->once()) + ->method('dump'); + + $writer = new TranslationWriter(); + $writer->addDumper('test', $dumper); + $writer->writeTranslations(new MessageCatalogue(array()), 'test'); + } + + public function testDisableBackup() + { + $dumper = $this->getMock('Symfony\Component\Translation\Dumper\DumperInterface'); + $dumper + ->expects($this->never()) + ->method('setBackup'); + $phpDumper = $this->getMock('Symfony\Component\Translation\Dumper\PhpFileDumper'); + $phpDumper + ->expects($this->once()) + ->method('setBackup'); + + $writer = new TranslationWriter(); + $writer->addDumper('test', $dumper); + $writer->addDumper('php', $phpDumper); + $writer->disableBackup(); + } +} diff --git a/src/Symfony/Component/Translation/Writer/TranslationWriter.php b/src/Symfony/Component/Translation/Writer/TranslationWriter.php index 44ac182d74..da88c1fc52 100644 --- a/src/Symfony/Component/Translation/Writer/TranslationWriter.php +++ b/src/Symfony/Component/Translation/Writer/TranslationWriter.php @@ -45,7 +45,9 @@ class TranslationWriter public function disableBackup() { foreach ($this->dumpers as $dumper) { - $dumper->setBackup(false); + if (method_exists($dumper, 'setBackup')) { + $dumper->setBackup(false); + } } } From 79474a6a0257ace07413b7c97f92b29d71c25bb4 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Fri, 11 Dec 2015 10:18:56 +0100 Subject: [PATCH 03/16] Profiler CSS position conflicts with JS detection --- .../Resources/views/Profiler/toolbar.css.twig | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig index c0456f6131..c629059321 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig @@ -416,9 +416,6 @@ .sf-toolbar-block .sf-toolbar-icon svg { top: 6px; } - .sf-toolbar-block-config:hover .sf-toolbar-info { - right: 0; - } .sf-toolbar-block-time .sf-toolbar-icon svg, .sf-toolbar-block-memory .sf-toolbar-icon svg { display: none; From d7b730f3e55e1b3ba3c391e0b80ccc3fd69733f1 Mon Sep 17 00:00:00 2001 From: Possum Date: Fri, 22 Jan 2016 08:50:32 +0100 Subject: [PATCH 04/16] Fixer findings. --- src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php | 1 + .../Console/Tests/Descriptor/AbstractDescriptorTest.php | 1 + .../Component/CssSelector/Tests/Node/AbstractNodeTest.php | 1 + .../CssSelector/Tests/Parser/Handler/AbstractHandlerTest.php | 2 ++ .../HttpFoundation/HttpFoundationRequestHandlerTest.php | 1 + src/Symfony/Component/HttpFoundation/Response.php | 1 + .../Tests/Fragment/RoutableFragmentRendererTest.php | 1 + .../Security/Tests/Core/Encoder/EncoderFactoryTest.php | 4 ++++ .../Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php | 1 + 9 files changed, 13 insertions(+) diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index 4399ca7728..26ba94a1bf 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -36,6 +36,7 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase trim($compiler->compile($node)->getSource()) ); } + protected function getVariableGetterWithoutStrictCheck($name) { if (PHP_VERSION_ID >= 50400) { diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index aab1cf3761..9cd979271e 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -82,6 +82,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase } abstract protected function getDescriptor(); + abstract protected function getFormat(); private function getDescriptionTestData(array $objects) diff --git a/src/Symfony/Component/CssSelector/Tests/Node/AbstractNodeTest.php b/src/Symfony/Component/CssSelector/Tests/Node/AbstractNodeTest.php index 16a3a34d64..932e8030dd 100644 --- a/src/Symfony/Component/CssSelector/Tests/Node/AbstractNodeTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Node/AbstractNodeTest.php @@ -28,5 +28,6 @@ abstract class AbstractNodeTest extends \PHPUnit_Framework_TestCase } abstract public function getToStringConversionTestData(); + abstract public function getSpecificityValueTestData(); } diff --git a/src/Symfony/Component/CssSelector/Tests/Parser/Handler/AbstractHandlerTest.php b/src/Symfony/Component/CssSelector/Tests/Parser/Handler/AbstractHandlerTest.php index a06dca013b..57afa5a242 100644 --- a/src/Symfony/Component/CssSelector/Tests/Parser/Handler/AbstractHandlerTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Parser/Handler/AbstractHandlerTest.php @@ -43,7 +43,9 @@ abstract class AbstractHandlerTest extends \PHPUnit_Framework_TestCase } abstract public function getHandleValueTestData(); + abstract public function getDontHandleValueTestData(); + abstract protected function generateHandler(); protected function assertStreamEmpty(TokenStream $stream) diff --git a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php index 4d4ac86fe7..e71a1fdfd8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php @@ -28,6 +28,7 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest { $this->requestHandler->handleRequest($this->getMockForm('name', 'GET')); } + /** * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException */ diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index a21e6b921c..0318b9be63 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -977,6 +977,7 @@ class Response } // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + /** * Is response invalid? * diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php index f0a1cf4084..0222998ea2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php @@ -65,6 +65,7 @@ class Renderer extends RoutableFragmentRenderer public function render($uri, Request $request, array $options = array()) { } + public function getName() { } diff --git a/src/Symfony/Component/Security/Tests/Core/Encoder/EncoderFactoryTest.php b/src/Symfony/Component/Security/Tests/Core/Encoder/EncoderFactoryTest.php index 85d4e91356..4fe60adcd1 100644 --- a/src/Symfony/Component/Security/Tests/Core/Encoder/EncoderFactoryTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Encoder/EncoderFactoryTest.php @@ -85,15 +85,19 @@ class SomeUser implements UserInterface public function getRoles() { } + public function getPassword() { } + public function getSalt() { } + public function getUsername() { } + public function eraseCredentials() { } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php index 731ab83561..89fe9be80f 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php @@ -87,6 +87,7 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected_parent, $parent_metadata); } + /** * Test MetaData merge with parent annotation. */ From a5c881182f2c471dac9b9fbd8b6d52375c39672d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 23 Jan 2016 17:38:15 +0100 Subject: [PATCH 05/16] sort bundles in config:dump-reference command This backports #17495 to the `2.3` branch. --- .../FrameworkBundle/Command/ConfigDumpReferenceCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index fa978b3ba9..e116d83e88 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -66,6 +66,11 @@ EOF if (empty($name)) { $output->writeln('Available registered bundles with their extension alias if available:'); + + usort($bundles, function($bundleA, $bundleB) { + return strcmp($bundleA->getName(), $bundleB->getName()); + }); + foreach ($bundles as $bundle) { $extension = $bundle->getContainerExtension(); $output->writeln($bundle->getName().($extension ? ': '.$extension->getAlias() : '')); From 65adb7282c24cdd0b4695a82e6b3fb4bb7170877 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Mon, 25 Jan 2016 01:05:43 +0100 Subject: [PATCH 06/16] add defaultNull to version --- .../Bundle/FrameworkBundle/DependencyInjection/Configuration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 936b9cf00d..909e165557 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -554,6 +554,7 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('base_url') ->children() ->scalarNode('version') + ->defaultNull() ->beforeNormalization() ->ifTrue(function ($v) { return '' === $v; }) ->then(function ($v) { return; }) From fb729eecfa82979a9779a462a34ac8e30291f5f9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 25 Jan 2016 08:27:56 +0100 Subject: [PATCH 07/16] fixed CS --- src/Symfony/Component/HttpFoundation/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 0318b9be63..65d435ba5d 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -976,12 +976,12 @@ class Response return $notModified; } - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html - /** * Is response invalid? * * @return bool + * + * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html */ public function isInvalid() { From cba206ab18b8705bf82d32f1c3a811cbd5f630ec Mon Sep 17 00:00:00 2001 From: Alex Bogomazov Date: Thu, 24 Dec 2015 01:45:26 +0300 Subject: [PATCH 08/16] [Finder] Check PHP version before applying a workaround for a PHP bug --- .../Finder/Iterator/FilterIterator.php | 22 ++++++++++--------- .../Iterator/RecursiveDirectoryIterator.php | 6 +++-- .../Component/Finder/Tests/FinderTest.php | 12 ++++++---- .../Tests/Iterator/FilterIteratorTest.php | 5 +++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Finder/Iterator/FilterIterator.php b/src/Symfony/Component/Finder/Iterator/FilterIterator.php index f4da44c4cd..24adeb68f9 100644 --- a/src/Symfony/Component/Finder/Iterator/FilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/FilterIterator.php @@ -12,9 +12,10 @@ namespace Symfony\Component\Finder\Iterator; /** - * This iterator just overrides the rewind method in order to correct a PHP bug. + * This iterator just overrides the rewind method in order to correct a PHP bug, + * which existed before version 5.5.23/5.6.7. * - * @see https://bugs.php.net/bug.php?id=49104 + * @see https://bugs.php.net/68557 * * @author Alex Bogomazov */ @@ -28,18 +29,19 @@ abstract class FilterIterator extends \FilterIterator */ public function rewind() { + if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) { + parent::rewind(); + + return; + } + $iterator = $this; while ($iterator instanceof \OuterIterator) { $innerIterator = $iterator->getInnerIterator(); - if ($innerIterator instanceof RecursiveDirectoryIterator) { - if ($innerIterator->isRewindable()) { - $innerIterator->next(); - $innerIterator->rewind(); - } - } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) { - $iterator->getInnerIterator()->next(); - $iterator->getInnerIterator()->rewind(); + if ($innerIterator instanceof \FilesystemIterator) { + $innerIterator->next(); + $innerIterator->rewind(); } $iterator = $iterator->getInnerIterator(); } diff --git a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php index 3f65d69269..402033a5c2 100644 --- a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php +++ b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php @@ -118,8 +118,10 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator return; } - // @see https://bugs.php.net/bug.php?id=49104 - parent::next(); + // @see https://bugs.php.net/68557 + if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) { + parent::next(); + } parent::rewind(); } diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index cee8bd7530..624d4547e5 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -458,7 +458,7 @@ class FinderTest extends Iterator\RealIteratorTestCase * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator * with inner FilesystemIterator in an invalid state. * - * @see https://bugs.php.net/bug.php?id=49104 + * @see https://bugs.php.net/68557 */ public function testMultipleLocations() { @@ -468,8 +468,12 @@ class FinderTest extends Iterator\RealIteratorTestCase ); // it is expected that there are test.py test.php in the tmpDir - $finder = $this->buildFinder(); - $finder->in($locations)->depth('< 1')->name('test.php'); + $finder = new Finder(); + $finder->in($locations) + // the default flag IGNORE_DOT_FILES fixes the problem indirectly + // so we set it to false for better isolation + ->ignoreDotFiles(false) + ->depth('< 1')->name('test.php'); $this->assertCount(1, $finder); } @@ -479,7 +483,7 @@ class FinderTest extends Iterator\RealIteratorTestCase * AppendIterator which does an unnecessary rewind which leaves * FilterIterator with inner FilesystemIterator in an invalid state. * - * @see https://bugs.php.net/bug.php?id=49104 + * @see https://bugs.php.net/68557 */ public function testMultipleLocationsWithSubDirectories() { diff --git a/src/Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php index 41e05a0a7b..4f12d142e7 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php @@ -43,8 +43,9 @@ class FilterIteratorTest extends RealIteratorTestCase ++$c; } - // This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator - // see https://bugs.php.net/bug.php?id=49104 + // This would fail in php older than 5.5.23/5.6.7 with \FilterIterator + // but works with Symfony\Component\Finder\Iterator\FilterIterator + // see https://bugs.php.net/68557 $this->assertEquals(1, $c); } } From f80e0eb143001d1d01998278d848e6ffcb548872 Mon Sep 17 00:00:00 2001 From: DZunke Date: Tue, 8 Dec 2015 09:03:22 +0100 Subject: [PATCH 09/16] [Form] Fix constraints could be null if not set --- .../Extension/Validator/Constraints/FormValidator.php | 2 +- .../Validator/Constraints/FormValidatorTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index f862970a7f..5792aa4082 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -45,7 +45,7 @@ class FormValidator extends ConstraintValidator // Validate the data against the constraints defined // in the form - $constraints = $config->getOption('constraints'); + $constraints = $config->getOption('constraints', array()); foreach ($constraints as $constraint) { foreach ($groups as $group) { if (in_array($group, $constraint->groups)) { diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index c440a0470a..1e30f237a5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -123,6 +123,17 @@ class FormValidatorTest extends AbstractConstraintValidatorTest $this->assertNoViolation(); } + public function testNotExistingConstraintIndex() + { + $object = new \stdClass(); + $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory); + $form = $form->setData($object)->getForm(); + + $this->validator->validate($form, new Form()); + + $this->assertNoViolation(); + } + public function testValidateConstraintsEvenIfNoCascadeValidation() { $object = $this->getMock('\stdClass'); From 898f3890ffadae149e0de04dbfdbed52f666738a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 25 Jan 2016 09:20:12 +0100 Subject: [PATCH 10/16] fixed typo --- .../Tests/Extension/Validator/Constraints/FormValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index 1e30f237a5..ca34a936dc 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -123,7 +123,7 @@ class FormValidatorTest extends AbstractConstraintValidatorTest $this->assertNoViolation(); } - public function testNotExistingConstraintIndex() + public function testMissingConstraintIndex() { $object = new \stdClass(); $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory); From 3dae8257f2f309b89e06aec3f4f6d52493f2add2 Mon Sep 17 00:00:00 2001 From: zorn Date: Mon, 7 Dec 2015 13:23:40 +1000 Subject: [PATCH 11/16] Able to load big xml files with DomCrawler --- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 9dd3daa503..a51463dd0f 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -230,7 +230,7 @@ class Crawler extends \SplObjectStorage if ('' !== trim($content)) { // remove the default namespace to make XPath expressions simpler - @$dom->loadXML(str_replace('xmlns', 'ns', $content), LIBXML_NONET); + @$dom->loadXML(str_replace('xmlns', 'ns', $content), LIBXML_NONET | (defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0)); } libxml_use_internal_errors($internalErrors); From 156cdb5ab0b393ce5516dae438d8274a740b3ce2 Mon Sep 17 00:00:00 2001 From: FlorianLB Date: Sat, 5 Dec 2015 11:52:14 +0100 Subject: [PATCH 12/16] [TwigBridge] add missing unit tests (AppVariable) --- .../Bridge/Twig/Tests/AppVariableTest.php | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/Symfony/Bridge/Twig/Tests/AppVariableTest.php diff --git a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php new file mode 100644 index 0000000000..c82d892557 --- /dev/null +++ b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php @@ -0,0 +1,150 @@ +appVariable = new AppVariable(); + } + + /** + * @dataProvider debugDataProvider + */ + public function testDebug($debugFlag) + { + $this->appVariable->setDebug($debugFlag); + + $this->assertEquals($debugFlag, $this->appVariable->getDebug()); + } + + public function debugDataProvider() + { + return array( + 'debug on' => array(true), + 'debug off' => array(false), + ); + } + + public function testEnvironment() + { + $this->appVariable->setEnvironment('dev'); + + $this->assertEquals('dev', $this->appVariable->getEnvironment()); + } + + public function testGetSession() + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + $request->method('getSession')->willReturn($session = new Session()); + + $this->setRequestStack($request); + + $this->assertEquals($session, $this->appVariable->getSession()); + } + + public function testGetSessionWithNoRequest() + { + $this->setRequestStack(null); + + $this->assertNull($this->appVariable->getSession()); + } + + public function testGetRequest() + { + $this->setRequestStack($request = new Request()); + + $this->assertEquals($request, $this->appVariable->getRequest()); + } + + public function testGetUser() + { + $this->setTokenStorage($user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface')); + + $this->assertEquals($user, $this->appVariable->getUser()); + } + + public function testGetUserWithUsernameAsTokenUser() + { + $this->setTokenStorage($user = 'username'); + + $this->assertNull($this->appVariable->getUser()); + } + + public function testGetUserWithNoToken() + { + $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'); + $this->appVariable->setTokenStorage($tokenStorage); + + $this->assertNull($this->appVariable->getUser()); + } + + /** + * @expectedException \RuntimeException + */ + public function testEnvironmentNotSet() + { + $this->appVariable->getEnvironment(); + } + + /** + * @expectedException \RuntimeException + */ + public function testDebugNotSet() + { + $this->appVariable->getDebug(); + } + + /** + * @expectedException \RuntimeException + */ + public function testGetUserWithTokenStorageNotSet() + { + $this->appVariable->getUser(); + } + + /** + * @expectedException \RuntimeException + */ + public function testGetRequestWithRequestStackNotSet() + { + $this->appVariable->getRequest(); + } + + /** + * @expectedException \RuntimeException + */ + public function testGetSessionWithRequestStackNotSet() + { + $this->appVariable->getSession(); + } + + protected function setRequestStack($request) + { + $requestStackMock = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $requestStackMock->method('getCurrentRequest')->willReturn($request); + + $this->appVariable->setRequestStack($requestStackMock); + } + + protected function setTokenStorage($user) + { + $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'); + $this->appVariable->setTokenStorage($tokenStorage); + + $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + $tokenStorage->method('getToken')->willReturn($token); + + $token->method('getUser')->willReturn($user); + } +} From 884368e7095073ced91be29a91571415ab65ff62 Mon Sep 17 00:00:00 2001 From: Stepan Anchugov Date: Fri, 22 Jan 2016 04:44:07 +0500 Subject: [PATCH 13/16] Throw for missing container extensions This covers cases when a bundle does not have an extension, which lead to FatalErrorException with ```Call to a member function getAlias() on null``` --- .../Bundle/FrameworkBundle/Command/AbstractConfigCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index 711934c73a..d1e0f9c771 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -57,6 +57,10 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand $bundles = $this->initializeBundles(); foreach ($bundles as $bundle) { if ($name === $bundle->getName()) { + if (!$bundle->getContainerExtension()) { + throw new \LogicException(sprintf('Bundle "%s" does not have a container extension.', $name)); + } + return $bundle->getContainerExtension(); } From 233e5b8df7481a32742f7f3175e0d14dab30857f Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Wed, 20 Jan 2016 17:27:56 +0100 Subject: [PATCH 14/16] [EventDispatcher] TraceableEventDispatcher resets listener priorities --- .../Debug/TraceableEventDispatcher.php | 7 +++--- .../Debug/TraceableEventDispatcherTest.php | 23 ++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index 35df8162b1..75ba2a760f 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -235,12 +235,12 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface private function preProcess($eventName) { foreach ($this->dispatcher->getListeners($eventName) as $listener) { - $this->dispatcher->removeListener($eventName, $listener); $info = $this->getListenerInfo($listener, $eventName); $name = isset($info['class']) ? $info['class'] : $info['type']; $wrappedListener = new WrappedListener($listener, $name, $this->stopwatch, $this); $this->wrappedListeners[$eventName][] = $wrappedListener; - $this->dispatcher->addListener($eventName, $wrappedListener); + $this->dispatcher->removeListener($eventName, $listener); + $this->dispatcher->addListener($eventName, $wrappedListener, $info['priority']); } } @@ -253,8 +253,9 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface continue; } // Unwrap listener + $priority = $this->getListenerPriority($eventName, $listener); $this->dispatcher->removeListener($eventName, $listener); - $this->dispatcher->addListener($eventName, $listener->getWrappedListener()); + $this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority); $info = $this->getListenerInfo($listener->getWrappedListener(), $eventName); if ($listener->wasCalled()) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php index 1d4a8c8506..2dd8292a1b 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php @@ -56,6 +56,23 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase $this->assertTrue($tdispatcher->hasListeners('foo')); } + public function testGetListenerPriority() + { + $dispatcher = new EventDispatcher(); + $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch()); + + $tdispatcher->addListener('foo', function () {}, 123); + + $listeners = $dispatcher->getListeners('foo'); + $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0])); + + // Verify that priority is preserved when listener is removed and re-added + // in preProcess() and postProcess(). + $tdispatcher->dispatch('foo', new Event()); + $listeners = $dispatcher->getListeners('foo'); + $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0])); + } + public function testAddRemoveSubscriber() { $dispatcher = new EventDispatcher(); @@ -138,12 +155,12 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase $dispatcher = new EventDispatcher(); $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch()); - $tdispatcher->addListener('foo', $listener1 = function () use (&$called) { $called[] = 'foo1'; }); - $tdispatcher->addListener('foo', $listener2 = function () use (&$called) { $called[] = 'foo2'; }); + $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10); + $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20); $tdispatcher->dispatch('foo'); - $this->assertEquals(array('foo1', 'foo2'), $called); + $this->assertSame(array('foo2', 'foo1'), $called); } public function testDispatchNested() From 6578806fc3417675bd991362e7c1f05abdd1cb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sun, 29 Nov 2015 00:02:58 +0100 Subject: [PATCH 15/16] [Request] Ignore invalid IP addresses sent by proxies Fixes symfony/symfony#15525 --- src/Symfony/Component/HttpFoundation/Request.php | 14 +++++++++++--- .../Component/HttpFoundation/Tests/RequestTest.php | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index d2af44626c..72bd9f1143 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -769,8 +769,7 @@ class Request $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP]))); $clientIps[] = $ip; // Complete the IP chain with the IP the request actually came from - - $ip = $clientIps[0]; // Fallback to this when the client IP falls into the range of trusted proxies + $firstTrustedIp = null; // Eliminate all IPs from the forwarded IP chain which are trusted proxies foreach ($clientIps as $key => $clientIp) { @@ -779,13 +778,22 @@ class Request $clientIps[$key] = $clientIp = $match[1]; } + if (!filter_var($clientIp, FILTER_VALIDATE_IP)) { + unset($clientIps[$key]); + } + if (IpUtils::checkIp($clientIp, self::$trustedProxies)) { unset($clientIps[$key]); + + // Fallback to this when the client IP falls into the range of trusted proxies + if (null === $firstTrustedIp) { + $firstTrustedIp = $clientIp; + } } } // Now the IP chain contains only untrusted proxies and the client IP - return $clientIps ? array_reverse($clientIps) : array($ip); + return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp); } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index e17953819b..d601204231 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -863,6 +863,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase // client IP with port array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88:12345, 127.0.0.1', array('127.0.0.1')), + + // invalid forwarded IP is ignored + array(array('88.88.88.88'), '127.0.0.1', 'unknown,88.88.88.88', array('127.0.0.1')), ); } From 0fe08a800e8fbcb65e899de54f7c3186df72d109 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 25 Jan 2016 10:56:38 +0100 Subject: [PATCH 16/16] fixed test --- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 9ddaa6b4c0..458cd88b7e 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -853,7 +853,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase // $expected $remoteAddr $httpForwarded $trustedProxies return array( array(array('127.0.0.1'), '127.0.0.1', 'for="_gazonk"', null), - array(array('_gazonk'), '127.0.0.1', 'for="_gazonk"', array('127.0.0.1')), + array(array('127.0.0.1'), '127.0.0.1', 'for="_gazonk"', array('127.0.0.1')), array(array('88.88.88.88'), '127.0.0.1', 'for="88.88.88.88:80"', array('127.0.0.1')), array(array('192.0.2.60'), '::1', 'for=192.0.2.60;proto=http;by=203.0.113.43', array('::1')), array(array('2620:0:1cfe:face:b00c::3', '192.0.2.43'), '::1', 'for=192.0.2.43, for=2620:0:1cfe:face:b00c::3', array('::1')),