From 6325b4caf6eeeb56cbecffb1af417c2c7f14c1fb Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 2 Jul 2015 11:55:36 +0200 Subject: [PATCH 01/19] [Form] Added upgrade notes for #15061 --- UPGRADE-2.7.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/UPGRADE-2.7.md b/UPGRADE-2.7.md index 5123df9205..ab1021fcdc 100644 --- a/UPGRADE-2.7.md +++ b/UPGRADE-2.7.md @@ -665,3 +665,57 @@ Security * `SwitchUserListener` * `AccessListener` * `RememberMeListener` + +UPGRADE FROM 2.7.1 to 2.7.2 +=========================== + +Form +---- + + * In order to fix a few regressions in the new `ChoiceList` implementation, + a few details had to be changed compared to 2.7. + + The legacy `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface` + now does not extend the new `Symfony\Component\Form\ChoiceList\ChoiceListInterface` + anymore. If you pass an implementation of the old interface in a context + where the new interface is required, wrap the list into a + `LegacyChoiceListAdapter`: + + Before: + + ```php + use Symfony\Component\Form\ChoiceList\ChoiceListInterface; + + function doSomething(ChoiceListInterface $choiceList) + { + // ... + } + + doSomething($legacyList); + ``` + + After: + + ```php + use Symfony\Component\Form\ChoiceList\ChoiceListInterface; + use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter; + + function doSomething(ChoiceListInterface $choiceList) + { + // ... + } + + doSomething(new LegacyChoiceListAdapter($legacyList)); + ``` + + The new `ChoiceListInterface` now has two additional methods + `getStructuredValues()` and `getOriginalKeys()`. You should add these methods + if you implement this interface. See their doc blocks and the implementation + of the core choice lists for inspiration. + + The method `ArrayKeyChoiceList::toArrayKey()` was marked as internal. This + method was never supposed to be used outside the class. + + The method `ChoiceListFactoryInterface::createView()` does not accept arrays + and `Traversable` instances anymore for the `$groupBy` parameter. Pass a + callable instead. From cf86a03b98f6e02871c34a2fb3cc3551d004cc7c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 2 Jul 2015 23:04:32 +0200 Subject: [PATCH 02/19] fix for legacy asset() with EmptyVersionStrategy --- src/Symfony/Bridge/Twig/Extension/AssetExtension.php | 12 ++++++++---- .../Twig/Tests/Extension/AssetExtensionTest.php | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php index d138b1de1e..f7b9c87500 100644 --- a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php @@ -108,11 +108,15 @@ class AssetExtension extends \Twig_Extension $v->setAccessible(true); $currentVersionStrategy = $v->getValue($package); - $f = new \ReflectionProperty($currentVersionStrategy, 'format'); - $f->setAccessible(true); - $format = $f->getValue($currentVersionStrategy); + if (property_exists($currentVersionStrategy, 'format')) { + $f = new \ReflectionProperty($currentVersionStrategy, 'format'); + $f->setAccessible(true); + $format = $f->getValue($currentVersionStrategy); - $v->setValue($package, new StaticVersionStrategy($version, $format)); + $v->setValue($package, new StaticVersionStrategy($version, $format)); + } else { + $v->setValue($package, new StaticVersionStrategy($version)); + } } try { diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AssetExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AssetExtensionTest.php index ab73179394..474d8c3395 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AssetExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AssetExtensionTest.php @@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\Extension\AssetExtension; use Symfony\Component\Asset\Package; use Symfony\Component\Asset\Packages; use Symfony\Component\Asset\PathPackage; +use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy; use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy; class AssetExtensionTest extends \PHPUnit_Framework_TestCase @@ -41,6 +42,16 @@ class AssetExtensionTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/foo/me.png?version=42', $extension->getAssetUrl('me.png', null, false, 42)); } + /** + * @group legacy + */ + public function testGetAssetUrlWithEmptyVersionStrategy() + { + $extension = $this->createExtension(new PathPackage('foo', new EmptyVersionStrategy())); + + $this->assertEquals('/foo/me.png?42', $extension->getAssetUrl('me.png', null, false, 42)); + } + private function createExtension(Package $package) { $foundationExtension = $this->getMockBuilder('Symfony\Bridge\Twig\Extension\HttpFoundationExtension')->disableOriginalConstructor()->getMock(); From 5f4015c3cded4f20f6333c60bd52156bc70b0086 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 3 Jul 2015 07:54:45 +0200 Subject: [PATCH 03/19] Enhance hhvm test skip message --- src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 115f599f56..563bd0997e 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -40,7 +40,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase public function testCompileTimeError() { if (defined('HHVM_VERSION')) { - $this->markTestSkipped('HHVM behaves differently in this test case.'); + $this->markTestSkipped('HHVM does not trigger strict notices.'); } // the ContextErrorException must not be loaded to test the workaround From 3233c2fc142210a60d7deba084de21ac82c99a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 3 Jul 2015 10:25:38 +0200 Subject: [PATCH 04/19] [Serializer] Fix Groups PHPDoc --- src/Symfony/Component/Serializer/Annotation/Groups.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Annotation/Groups.php b/src/Symfony/Component/Serializer/Annotation/Groups.php index 9e7801f842..519837a55b 100644 --- a/src/Symfony/Component/Serializer/Annotation/Groups.php +++ b/src/Symfony/Component/Serializer/Annotation/Groups.php @@ -30,7 +30,8 @@ class Groups /** * @param array $data - * @throws \InvalidArgumentException + * + * @throws InvalidArgumentException */ public function __construct(array $data) { @@ -52,7 +53,7 @@ class Groups } /** - * Gets groups + * Gets groups. * * @return array */ From da5218f2ae7fb3724c08dbe047e196766374ac49 Mon Sep 17 00:00:00 2001 From: Dave Hulbert Date: Fri, 3 Jul 2015 22:02:27 +0100 Subject: [PATCH 05/19] Remove var not used due to returning early (introduced in 8982c32) --- src/Symfony/Component/HttpFoundation/Request.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 8babb395c5..84b3a69ade 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -476,7 +476,6 @@ class Request */ public function __toString() { - $content = ''; try { $content = $this->getContent(); } catch (\LogicException $e) { From e195fd7c1bccde4cefea2b9766ffb8f715de5405 Mon Sep 17 00:00:00 2001 From: Kevin Robatel Date: Fri, 3 Jul 2015 16:45:06 +0200 Subject: [PATCH 06/19] Remove duplicate example --- UPGRADE-3.0.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 14520c1c6f..2d2590a7c1 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -273,10 +273,6 @@ UPGRADE FROM 2.x to 3.0 echo $form->getErrors(true, false); ``` - ```php - echo $form->getErrors(true, false); - ``` - ### FrameworkBundle * The `getRequest` method of the base `Controller` class has been deprecated From 2bd8fb8f979327c61caa2e137acba27edf1bf028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 3 Jul 2015 14:43:05 +0200 Subject: [PATCH 07/19] [Serializer] Fix Groups tests. --- .../Component/Serializer/Tests/Annotation/GroupsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php index b427325f08..72b877729d 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php @@ -19,7 +19,7 @@ use Symfony\Component\Serializer\Annotation\Groups; class GroupsTest extends \PHPUnit_Framework_TestCase { /** - * @expectedException \InvalidArgumentException + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testEmptyGroupsParameter() { @@ -27,7 +27,7 @@ class GroupsTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testNotAnArrayGroupsParameter() { @@ -35,7 +35,7 @@ class GroupsTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testInvalidGroupsParameter() { From 9b0dfd426755d24701ccd16ddf83e9d11122693d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 5 Jul 2015 10:40:11 +0200 Subject: [PATCH 08/19] [Security] allow to use `method` in XML configs Before this change, you always had to use the `methods` key which is inconsistent compared to other options like `roles` and `ips` for which it was possible to use their singular versions. --- .../SecurityBundle/DependencyInjection/MainConfiguration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index 73498f76da..c79868c523 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -158,6 +158,7 @@ class MainConfiguration implements ConfigurationInterface ->cannotBeOverwritten() ->prototype('array') ->fixXmlConfig('ip') + ->fixXmlConfig('method') ->children() ->scalarNode('requires_channel')->defaultNull()->end() ->scalarNode('path') From 0096266009223b569172a978a9083e80efd31754 Mon Sep 17 00:00:00 2001 From: Daniel Wehner Date: Fri, 26 Jun 2015 15:47:25 +0200 Subject: [PATCH 09/19] Add a way to reset the singleton --- .../HttpFoundation/File/MimeType/MimeTypeGuesser.php | 7 +++++++ .../Component/HttpFoundation/Tests/File/FileTest.php | 12 ++++++++++++ .../Tests/File/Fixtures/other-file.example | 0 3 files changed, 19 insertions(+) create mode 100644 src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/other-file.example diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php index 81b2b02bd4..4ae6487bad 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php @@ -67,6 +67,13 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface return self::$instance; } + /** + * Resets the singleton instance. + */ + public static function reset() { + self::$instance = null; + } + /** * Registers all natively provided mime type guessers. */ diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php index 1f89c391d5..f325d003c6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php @@ -45,6 +45,18 @@ class FileTest extends \PHPUnit_Framework_TestCase $this->assertEquals('gif', $file->guessExtension()); } + public function testGuessExtensionWithReset() { + $file = new File(__DIR__.'/Fixtures/other-file.example'); + $guesser = $this->createMockGuesser($file->getPathname(), 'image/gif'); + MimeTypeGuesser::getInstance()->register($guesser); + + $this->assertEquals('gif', $file->guessExtension()); + + MimeTypeGuesser::reset(); + + $this->assertNull($file->guessExtension()); + } + public function testConstructWhenFileNotExists() { $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/other-file.example b/src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/other-file.example new file mode 100644 index 0000000000..e69de29bb2 From e3b225f4ba5e1cd220eb4f525d40d66a9c8d61e9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 5 Jul 2015 15:20:07 +0200 Subject: [PATCH 10/19] fixed CS --- .../Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php | 3 ++- src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php index 4ae6487bad..ecc8a30ac2 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php @@ -70,7 +70,8 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface /** * Resets the singleton instance. */ - public static function reset() { + public static function reset() + { self::$instance = null; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php index f325d003c6..08b7cccb52 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/FileTest.php @@ -45,7 +45,8 @@ class FileTest extends \PHPUnit_Framework_TestCase $this->assertEquals('gif', $file->guessExtension()); } - public function testGuessExtensionWithReset() { + public function testGuessExtensionWithReset() + { $file = new File(__DIR__.'/Fixtures/other-file.example'); $guesser = $this->createMockGuesser($file->getPathname(), 'image/gif'); MimeTypeGuesser::getInstance()->register($guesser); From 464b67ed09668168cabfd77b6b3cfa26ceb1b0b0 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 5 Jul 2015 16:01:47 +0200 Subject: [PATCH 11/19] fix CS --- .../Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php | 4 ++-- src/Symfony/Component/BrowserKit/Cookie.php | 1 - .../Component/DependencyInjection/Dumper/PhpDumper.php | 8 ++++---- src/Symfony/Component/DomCrawler/Tests/FormTest.php | 1 - src/Symfony/Component/Form/PreloadedExtension.php | 6 +++--- .../Component/HttpFoundation/Tests/RequestTest.php | 1 - .../Tests/EventListener/FragmentListenerTest.php | 1 - .../Component/Routing/Matcher/Dumper/PhpMatcherDumper.php | 6 +++--- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php index eacbd4f3c9..482b4d7ed7 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php @@ -91,7 +91,7 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase 'utf8' => 'foo', array( 'nonutf8' => DbalLogger::BINARY_DATA_VALUE, - ) + ), ) ) ; @@ -100,7 +100,7 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase 'utf8' => 'foo', array( 'nonutf8' => "\x7F\xFF", - ) + ), )); } diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index 18b9324403..e690cdacd5 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -82,7 +82,6 @@ class Cookie $this->expires = $timestampAsDateTime->getTimestamp(); } - } /** diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 64d5fb9bb6..db0a9f97d2 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -797,8 +797,8 @@ EOF; if (count($scopes = $this->container->getScopes()) > 0) { $code .= "\n"; - $code .= " \$this->scopes = ".$this->dumpValue($scopes).";\n"; - $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren()).";\n"; + $code .= ' $this->scopes = '.$this->dumpValue($scopes).";\n"; + $code .= ' $this->scopeChildren = '.$this->dumpValue($this->container->getScopeChildren()).";\n"; } $code .= $this->addMethodMap(); @@ -843,8 +843,8 @@ EOF; $code .= "\n"; if (count($scopes = $this->container->getScopes()) > 0) { - $code .= " \$this->scopes = ".$this->dumpValue($scopes).";\n"; - $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren()).";\n"; + $code .= ' $this->scopes = '.$this->dumpValue($scopes).";\n"; + $code .= ' $this->scopeChildren = '.$this->dumpValue($this->container->getScopeChildren()).";\n"; } else { $code .= " \$this->scopes = array();\n"; $code .= " \$this->scopeChildren = array();\n"; diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index c657e3639e..79b1a3b118 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -805,7 +805,6 @@ class FormTest extends \PHPUnit_Framework_TestCase */ public function testFormRegistrySetArrayOnNotCompoundField() { - $registry = new FormFieldRegistry(); $registry->add($this->getFormFieldMock('bar')); diff --git a/src/Symfony/Component/Form/PreloadedExtension.php b/src/Symfony/Component/Form/PreloadedExtension.php index f70ca8d455..6b4f9ef6a1 100644 --- a/src/Symfony/Component/Form/PreloadedExtension.php +++ b/src/Symfony/Component/Form/PreloadedExtension.php @@ -38,9 +38,9 @@ class PreloadedExtension implements FormExtensionInterface /** * Creates a new preloaded extension. * - * @param FormTypeInterface[] $types The types that the extension should support. - * @param array[FormTypeExtensionInterface[]] typeExtensions The type extensions that the extension should support. - * @param FormTypeGuesserInterface|null $typeGuesser The guesser that the extension should support. + * @param FormTypeInterface[] $types The types that the extension should support. + * @param array[FormTypeExtensionInterface[]] $typeExtensions The type extensions that the extension should support. + * @param FormTypeGuesserInterface|null $typeGuesser The guesser that the extension should support. */ public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser = null) { diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 990d3a842d..366b555f92 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -939,7 +939,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase } /** - * * @dataProvider getContentCantBeCalledTwiceWithResourcesProvider */ public function testGetContentCanBeCalledTwiceWithResources($first, $second) diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php index 18edee6123..fd5d63b167 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php @@ -34,7 +34,6 @@ class FragmentListenerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($request->query->has('_path')); } - public function testOnlyTriggeredIfControllerWasNotDefinedYet() { $request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'); diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 49d137f4ab..605ee560eb 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -216,11 +216,11 @@ EOF; $conditions[] = sprintf("rtrim(\$pathinfo, '/') === %s", var_export(rtrim(str_replace('\\', '', $m['url']), '/'), true)); $hasTrailingSlash = true; } else { - $conditions[] = sprintf("\$pathinfo === %s", var_export(str_replace('\\', '', $m['url']), true)); + $conditions[] = sprintf('$pathinfo === %s', var_export(str_replace('\\', '', $m['url']), true)); } } else { if ($compiledRoute->getStaticPrefix() && $compiledRoute->getStaticPrefix() !== $parentPrefix) { - $conditions[] = sprintf("0 === strpos(\$pathinfo, %s)", var_export($compiledRoute->getStaticPrefix(), true)); + $conditions[] = sprintf('0 === strpos($pathinfo, %s)', var_export($compiledRoute->getStaticPrefix(), true)); } $regex = $compiledRoute->getRegex(); @@ -228,7 +228,7 @@ EOF; $regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2); $hasTrailingSlash = true; } - $conditions[] = sprintf("preg_match(%s, \$pathinfo, \$matches)", var_export($regex, true)); + $conditions[] = sprintf('preg_match(%s, $pathinfo, $matches)', var_export($regex, true)); $matches = true; } From 15886b618e40fd9f943e46c0bccc6b7fc115ec12 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Tue, 7 Jul 2015 14:03:46 +0200 Subject: [PATCH 12/19] [Twig][Bridge] replaced `extends` with `use` in bootstrap_3_horizontal_layout.html.twig --- .../views/Form/bootstrap_3_horizontal_layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig index 6fc226da4f..f6b8671513 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig @@ -1,4 +1,4 @@ -{% extends "bootstrap_3_layout.html.twig" %} +{% use "bootstrap_3_layout.html.twig" %} {% block form_start -%} {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %} From 4a72c441d583557282df06a2252e7c06ac83f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 7 Jul 2015 14:38:28 +0200 Subject: [PATCH 13/19] [DependencyInjection] Freeze also FrozenParameterBag::remove --- .../ParameterBag/FrozenParameterBag.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php index dc936a0bd6..3ea6d9636b 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php @@ -69,4 +69,14 @@ class FrozenParameterBag extends ParameterBag { throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); } + + /** + * {@inheritdoc} + * + * @api + */ + public function remove($name) + { + throw new LogicException('Impossible to call remove() on a frozen ParameterBag.'); + } } From 2aff5660b2eb41552640545f6e672307170b61bc Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Tue, 7 Jul 2015 16:19:30 +0200 Subject: [PATCH 14/19] [Finder] Command::addAtIndex() fails with Command instance argument --- .../Component/Finder/Shell/Command.php | 2 +- .../Finder/Tests/Shell/CommandTest.php | 162 ++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Finder/Tests/Shell/CommandTest.php diff --git a/src/Symfony/Component/Finder/Shell/Command.php b/src/Symfony/Component/Finder/Shell/Command.php index ab070346fc..c91dd16161 100644 --- a/src/Symfony/Component/Finder/Shell/Command.php +++ b/src/Symfony/Component/Finder/Shell/Command.php @@ -289,7 +289,7 @@ class Command */ public function addAtIndex($bit, $index) { - array_splice($this->bits, $index, 0, $bit); + array_splice($this->bits, $index, 0, $bit instanceof self ? array($bit) : $bit); return $this; } diff --git a/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php new file mode 100644 index 0000000000..8c6c0064cd --- /dev/null +++ b/src/Symfony/Component/Finder/Tests/Shell/CommandTest.php @@ -0,0 +1,162 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Finder\Tests\Shell; + +use Symfony\Component\Finder\Shell\Command; + +class CommandTest extends \PHPUnit_Framework_TestCase +{ + public function testCreate() + { + $this->assertInstanceOf('Symfony\Component\Finder\Shell\Command', Command::create()); + } + + public function testAdd() + { + $cmd = Command::create()->add('--force'); + $this->assertSame('--force', $cmd->join()); + } + + public function testAddAsFirst() + { + $cmd = Command::create()->add('--force'); + + $cmd->addAtIndex(Command::create()->add('-F'), 0); + $this->assertSame('-F --force', $cmd->join()); + } + + public function testAddAsLast() + { + $cmd = Command::create()->add('--force'); + + $cmd->addAtIndex(Command::create()->add('-F'), 1); + $this->assertSame('--force -F', $cmd->join()); + } + + public function testAddInBetween() + { + $cmd = Command::create()->add('--force'); + $cmd->addAtIndex(Command::create()->add('-F'), 0); + + $cmd->addAtIndex(Command::create()->add('-X'), 1); + $this->assertSame('-F -X --force', $cmd->join()); + } + + public function testCount() + { + $cmd = Command::create(); + $this->assertSame(0, $cmd->length()); + + $cmd->add('--force'); + $this->assertSame(1, $cmd->length()); + + $cmd->add('--run'); + $this->assertSame(2, $cmd->length()); + } + + public function testTop() + { + $cmd = Command::create()->add('--force'); + + $cmd->top('--run'); + $this->assertSame('--run --force', $cmd->join()); + } + + public function testTopLabeled() + { + $cmd = Command::create()->add('--force'); + + $cmd->top('--run'); + $cmd->ins('--something'); + $cmd->top('--something'); + $this->assertSame('--something --run --force ', $cmd->join()); + } + + public function testArg() + { + $cmd = Command::create()->add('--force'); + + $cmd->arg('--run'); + $this->assertSame('--force \'--run\'', $cmd->join()); + } + + public function testCmd() + { + $cmd = Command::create()->add('--force'); + + $cmd->cmd('run'); + $this->assertSame('--force run', $cmd->join()); + } + + public function testInsDuplicateLabelException() + { + $cmd = Command::create()->add('--force'); + + $cmd->ins('label'); + $this->setExpectedException('RuntimeException'); + $cmd->ins('label'); + } + + public function testEnd() + { + $parent = Command::create(); + $cmd = Command::create($parent); + + $this->assertSame($parent, $cmd->end()); + } + + public function testEndNoParentException() + { + $cmd = Command::create(); + + $this->setExpectedException('RuntimeException'); + $cmd->end(); + } + + public function testGetMissingLabelException() + { + $cmd = Command::create(); + + $this->setExpectedException('RuntimeException'); + $cmd->get('invalid'); + } + + public function testErrorHandler() + { + $cmd = Command::create(); + $handler = function() { return 'error-handler'; }; + $cmd->setErrorHandler($handler); + + $this->assertSame($handler, $cmd->getErrorHandler()); + } + + public function testExecute() + { + $cmd = Command::create(); + $cmd->add('php'); + $cmd->add('--version'); + $result = $cmd->execute(); + + $this->assertTrue(is_array($result)); + $this->assertNotEmpty($result); + $this->assertRegexp('/PHP|HipHop/', $result[0]); + } + + public function testCastToString() + { + $cmd = Command::create(); + $cmd->add('--force'); + $cmd->add('--run'); + + $this->assertSame('--force --run', (string) $cmd); + } +} From 1dac1277a37d1b7cb037418d8456564331ab1559 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Tue, 7 Jul 2015 21:01:23 +0200 Subject: [PATCH 15/19] [2.6] Static Code Analysis for Components and Bundles --- .../Command/TranslationDebugCommand.php | 4 ++-- .../Command/TranslationUpdateCommand.php | 6 +++--- .../Console/Descriptor/TextDescriptor.php | 12 ++++++------ .../DependencyInjection/FrameworkExtension.php | 12 ++++++------ .../CacheClearCommand/CacheClearCommandTest.php | 2 +- .../Tests/Command/TranslationDebugCommandTest.php | 2 +- .../Console/Descriptor/AbstractDescriptorTest.php | 2 +- .../DependencyInjection/MainConfiguration.php | 2 +- .../Security/UserProvider/InMemoryFactory.php | 2 +- .../Bundle/TwigBundle/Command/DebugCommand.php | 4 ++-- .../TwigBundle/DependencyInjection/TwigExtension.php | 2 +- .../Tests/DependencyInjection/TwigExtensionTest.php | 6 ++---- src/Symfony/Component/Config/Util/XmlUtils.php | 2 +- src/Symfony/Component/Console/Helper/ProgressBar.php | 6 +++--- .../Component/Console/Question/ChoiceQuestion.php | 3 ++- src/Symfony/Component/Debug/DebugClassLoader.php | 7 ++++--- .../Component/Debug/Tests/DebugClassLoaderTest.php | 4 ++-- .../Component/Debug/Tests/ErrorHandlerTest.php | 2 +- .../ClassNotFoundFatalErrorHandlerTest.php | 4 ++-- .../UndefinedFunctionFatalErrorHandlerTest.php | 2 +- .../UndefinedMethodFatalErrorHandlerTest.php | 2 +- .../Filesystem/Tests/FilesystemTestCase.php | 4 ++-- .../Session/Storage/Handler/PdoSessionHandler.php | 6 +++--- .../Security/Core/Tests/Util/SecureRandomTest.php | 2 +- .../Component/Translation/Loader/JsonFileLoader.php | 2 +- .../Component/Translation/Tests/TranslatorTest.php | 2 +- 26 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 0f8ab152d9..1773794dea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -95,7 +95,7 @@ EOF ); foreach ($bundlePaths as $path) { - $path = $path.'views'; + $path .= 'views'; if (is_dir($path)) { $this->getContainer()->get('translation.extractor')->extract($path, $extractedCatalogue); } @@ -104,7 +104,7 @@ EOF // Load defined messages $currentCatalogue = new MessageCatalogue($locale); foreach ($bundlePaths as $path) { - $path = $path.'translations'; + $path .= 'translations'; if (is_dir($path)) { $loader->loadMessages($path, $currentCatalogue); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index c2b29cbc18..0e3cd824ec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -108,7 +108,7 @@ EOF $extractor = $this->getContainer()->get('translation.extractor'); $extractor->setPrefix($input->getOption('prefix')); foreach ($transPaths as $path) { - $path = $path.'views'; + $path .= 'views'; if (is_dir($path)) { $extractor->extract($path, $extractedCatalogue); } @@ -119,7 +119,7 @@ EOF $output->writeln('Loading translation files'); $loader = $this->getContainer()->get('translation.loader'); foreach ($transPaths as $path) { - $path = $path.'translations'; + $path .= 'translations'; if (is_dir($path)) { $loader->loadMessages($path, $currentCatalogue); } @@ -168,7 +168,7 @@ EOF $output->writeln('Writing files'); $bundleTransPath = false; foreach ($transPaths as $path) { - $path = $path.'translations'; + $path .= 'translations'; if (is_dir($path)) { $bundleTransPath = $path; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 43297595df..13ac2a2bb2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -174,7 +174,7 @@ class TextDescriptor extends Descriptor $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds(); $maxTags = array(); - foreach ($serviceIds as $key => $serviceId) { + foreach ($serviceIds as $key => $serviceId) { $definition = $this->resolveServiceDefinition($builder, $serviceId); if ($definition instanceof Definition) { // filter out private services unless shown explicitly @@ -212,7 +212,7 @@ class TextDescriptor extends Descriptor foreach ($definition->getTag($showTag) as $key => $tag) { $tagValues = array(); foreach ($tagsNames as $tagName) { - $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : ""; + $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : ''; } if (0 === $key) { $table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass()))); @@ -225,10 +225,10 @@ class TextDescriptor extends Descriptor } } elseif ($definition instanceof Alias) { $alias = $definition; - $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, "") : array())); + $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, '') : array())); } else { // we have no information (happens with "service_container") - $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, "") : array())); + $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, '') : array())); } } @@ -245,7 +245,7 @@ class TextDescriptor extends Descriptor : array(); $description[] = sprintf('Service Id %s', isset($options['id']) ? $options['id'] : '-'); - $description[] = sprintf('Class %s', $definition->getClass() ?: "-"); + $description[] = sprintf('Class %s', $definition->getClass() ?: '-'); $tags = $definition->getTags(); if (count($tags)) { @@ -269,7 +269,7 @@ class TextDescriptor extends Descriptor $description[] = sprintf('Abstract %s', $definition->isAbstract() ? 'yes' : 'no'); if ($definition->getFile()) { - $description[] = sprintf('Required File %s', $definition->getFile() ? $definition->getFile() : '-'); + $description[] = sprintf('Required File %s', $definition->getFile() ?: '-'); } if ($definition->getFactoryClass()) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index ac536e8d88..40c6950cf2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -642,22 +642,22 @@ class FrameworkExtension extends Extension if (class_exists('Symfony\Component\Validator\Validator')) { $r = new \ReflectionClass('Symfony\Component\Validator\Validator'); - $dirs[] = dirname($r->getFilename()).'/Resources/translations'; + $dirs[] = dirname($r->getFileName()).'/Resources/translations'; } if (class_exists('Symfony\Component\Form\Form')) { $r = new \ReflectionClass('Symfony\Component\Form\Form'); - $dirs[] = dirname($r->getFilename()).'/Resources/translations'; + $dirs[] = dirname($r->getFileName()).'/Resources/translations'; } if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) { $r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException'); - $dirs[] = dirname($r->getFilename()).'/../Resources/translations'; + $dirs[] = dirname($r->getFileName()).'/../Resources/translations'; } $overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations'; foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { $reflection = new \ReflectionClass($class); - if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) { + if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) { $dirs[] = $dir; } if (is_dir($dir = sprintf($overridePath, $bundle))) { @@ -775,7 +775,7 @@ class FrameworkExtension extends Extension foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); - if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) { + if (is_file($file = dirname($reflection->getFileName()).'/Resources/config/validation.xml')) { $files[] = realpath($file); $container->addResource(new FileResource($file)); } @@ -790,7 +790,7 @@ class FrameworkExtension extends Extension foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); - if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) { + if (is_file($file = dirname($reflection->getFileName()).'/Resources/config/validation.yml')) { $files[] = realpath($file); $container->addResource(new FileResource($file)); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php index 78ab561df1..745e015d57 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php @@ -24,7 +24,7 @@ class CacheClearCommandTest extends TestCase { $this->fs = new Filesystem(); $this->kernel = new TestAppKernel('test', true); - $this->rootDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('sf2_cache_'); + $this->rootDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('sf2_cache_', true); $this->kernel->setRootDir($this->rootDir); $this->fs->mkdir($this->rootDir); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index aed3513d0c..4ec50ebbe0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php @@ -56,7 +56,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->fs = new Filesystem(); - $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation'); + $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); $this->fs->mkdir($this->translationDir.'/Resources/translations'); $this->fs->mkdir($this->translationDir.'/Resources/views'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php index 481744aac0..14a69e6736 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php @@ -98,7 +98,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase { $data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter()); - array_push($data[0], array('parameter' => 'database_name')); + $data[0][] = array('parameter' => 'database_name'); return $data; } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index a1522fefc0..463a889082 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -286,7 +286,7 @@ class MainConfiguration implements ConfigurationInterface ->arrayNode('anonymous') ->canBeUnset() ->children() - ->scalarNode('key')->defaultValue(uniqid())->end() + ->scalarNode('key')->defaultValue(uniqid('', true))->end() ->end() ->end() ->arrayNode('switch_user') diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php index 5debce9adb..b184385f22 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/UserProvider/InMemoryFactory.php @@ -54,7 +54,7 @@ class InMemoryFactory implements UserProviderFactoryInterface ->useAttributeAsKey('name') ->prototype('array') ->children() - ->scalarNode('password')->defaultValue(uniqid())->end() + ->scalarNode('password')->defaultValue(uniqid('', true))->end() ->arrayNode('roles') ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end() ->prototype('scalar')->end() diff --git a/src/Symfony/Bundle/TwigBundle/Command/DebugCommand.php b/src/Symfony/Bundle/TwigBundle/Command/DebugCommand.php index f98fc8d457..2d1c71b1ad 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/DebugCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/DebugCommand.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** - * Lists twig functions, filters, globals and tests present in the current project + * Lists twig functions, filters, globals and tests present in the current project. * * @author Jordi Boggiano */ @@ -111,7 +111,7 @@ EOF if ($type === 'functions' || $type === 'filters') { $args = array(); $cb = $entity->getCallable(); - if (is_null($cb)) { + if (null === $cb) { return; } if (is_array($cb)) { diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 93a9a37728..466963ad3d 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -75,7 +75,7 @@ class TwigExtension extends Extension } $reflection = new \ReflectionClass($class); - if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) { + if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/views')) { $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle); } } diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 05d8dd20d4..9987f1a05d 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -156,10 +156,8 @@ class TwigExtensionTest extends TestCase $def = $container->getDefinition('twig.loader.filesystem'); $paths = array(); foreach ($def->getMethodCalls() as $call) { - if ('addPath' === $call[0]) { - if (false === strpos($call[1][0], 'Form')) { - $paths[] = $call[1]; - } + if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) { + $paths[] = $call[1]; } } diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index 2ef881df81..d8d4eaa3b1 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -196,7 +196,7 @@ class XmlUtils return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw); case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)): $raw = $value; - $cast = intval($value); + $cast = (int) $value; return '0' == $value[1] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw); case 'true' === $lowercaseValue: diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 893664e412..1cae64b6e5 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -370,7 +370,7 @@ class ProgressBar } /** - * Sets whether to overwrite the progressbar, false for new line + * Sets whether to overwrite the progressbar, false for new line. * * @param bool $overwrite */ @@ -397,8 +397,8 @@ class ProgressBar $this->max = $step; } - $prevPeriod = intval($this->step / $this->redrawFreq); - $currPeriod = intval($step / $this->redrawFreq); + $prevPeriod = (int) ($this->step / $this->redrawFreq); + $currPeriod = (int) ($step / $this->redrawFreq); $this->step = $step; $this->percent = $this->max ? (float) $this->step / $this->max : 0; if ($prevPeriod !== $currPeriod || $this->max === $step) { diff --git a/src/Symfony/Component/Console/Question/ChoiceQuestion.php b/src/Symfony/Component/Console/Question/ChoiceQuestion.php index e1da7a8c5e..7a67e4c3a3 100644 --- a/src/Symfony/Component/Console/Question/ChoiceQuestion.php +++ b/src/Symfony/Component/Console/Question/ChoiceQuestion.php @@ -137,7 +137,8 @@ class ChoiceQuestion extends Question if (empty($choices[$value])) { throw new \InvalidArgumentException(sprintf($errorMessage, $value)); } - array_push($multiselectChoices, $choices[$value]); + + $multiselectChoices[] = $choices[$value]; } if ($multiselect) { diff --git a/src/Symfony/Component/Debug/DebugClassLoader.php b/src/Symfony/Component/Debug/DebugClassLoader.php index b70a4c4ac3..a82f101b22 100644 --- a/src/Symfony/Component/Debug/DebugClassLoader.php +++ b/src/Symfony/Component/Debug/DebugClassLoader.php @@ -37,6 +37,7 @@ class DebugClassLoader * @param callable|object $classLoader * * @api + * * @deprecated since 2.5, passing an object is deprecated and support for it will be removed in 3.0 */ public function __construct($classLoader) @@ -69,7 +70,7 @@ class DebugClassLoader } /** - * Wraps all autoloaders + * Wraps all autoloaders. */ public static function enable() { @@ -117,7 +118,7 @@ class DebugClassLoader } /** - * Finds a file by class name + * Finds a file by class name. * * @param string $class A class name to resolve to file * @@ -187,7 +188,7 @@ class DebugClassLoader } if (self::$caseCheck && preg_match('#([/\\\\][a-zA-Z_\x7F-\xFF][a-zA-Z0-9_\x7F-\xFF]*)+\.(php|hh)$#D', $file, $tail)) { $tail = $tail[0]; - $real = $refl->getFilename(); + $real = $refl->getFileName(); if (2 === self::$caseCheck) { // realpath() on MacOSX doesn't normalize the case of characters diff --git a/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php index 8435397f66..9c4e23a2c5 100644 --- a/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php @@ -112,10 +112,10 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase restore_exception_handler(); $this->assertStringStartsWith(__FILE__, $exception->getFile()); if (PHP_VERSION_ID < 70000) { - $this->assertRegexp('/^Runtime Notice: Declaration/', $exception->getMessage()); + $this->assertRegExp('/^Runtime Notice: Declaration/', $exception->getMessage()); $this->assertEquals(E_STRICT, $exception->getSeverity()); } else { - $this->assertRegexp('/^Warning: Declaration/', $exception->getMessage()); + $this->assertRegExp('/^Warning: Declaration/', $exception->getMessage()); $this->assertEquals(E_WARNING, $exception->getSeverity()); } } catch (\Exception $exception) { diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 033b1c7f72..3b0cc7bdfa 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -77,7 +77,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase $this->assertEquals(E_NOTICE, $exception->getSeverity()); $this->assertEquals(__FILE__, $exception->getFile()); - $this->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage()); + $this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage()); $this->assertArrayHasKey('foobar', $exception->getContext()); $trace = $exception->getTrace(); diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index 6ac3374d8e..26eeede026 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -61,7 +61,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase array_map('spl_autoload_register', $autoloaders); } - $this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception); + $this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception); $this->assertSame($translatedMessage, $exception->getMessage()); $this->assertSame($error['type'], $exception->getSeverity()); $this->assertSame($error['file'], $exception->getFile()); @@ -197,6 +197,6 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase $handler = new ClassNotFoundFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceof('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception); + $this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception); } } diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php index ffe9edb062..795b74781c 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php @@ -24,7 +24,7 @@ class UndefinedFunctionFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase $handler = new UndefinedFunctionFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceof('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception); + $this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception); // class names are case insensitive and PHP/HHVM do not return the same $this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage())); $this->assertSame($error['type'], $exception->getSeverity()); diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index 7837d1daa6..794bf4c3ab 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -24,7 +24,7 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase $handler = new UndefinedMethodFatalErrorHandler(); $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); - $this->assertInstanceof('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception); + $this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception); $this->assertSame($translatedMessage, $exception->getMessage()); $this->assertSame($error['type'], $exception->getSeverity()); $this->assertSame($error['file'], $exception->getFile()); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php index 80cd57e809..74802fc314 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php @@ -16,7 +16,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase private $umask; /** - * @var string $workspace + * @var string */ protected $workspace = null; @@ -40,7 +40,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase protected function setUp() { $this->umask = umask(0); - $this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000); + $this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000); mkdir($this->workspace, 0777, true); $this->workspace = realpath($this->workspace); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index 32b73968db..48e81ee0f1 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -126,7 +126,7 @@ class PdoSessionHandler implements \SessionHandlerInterface private $lockMode = self::LOCK_TRANSACTIONAL; /** - * It's an array to support multiple reads before closing which is manual, non-standard usage + * It's an array to support multiple reads before closing which is manual, non-standard usage. * * @var \PDOStatement[] An array of statements to release advisory locks */ @@ -483,7 +483,7 @@ class PdoSessionHandler implements \SessionHandlerInterface if ('sqlite' === $this->driver) { $this->pdo->exec('ROLLBACK'); } else { - $this->pdo->rollback(); + $this->pdo->rollBack(); } $this->inTransaction = false; } @@ -680,7 +680,7 @@ class PdoSessionHandler implements \SessionHandlerInterface } /** - * Return a PDO instance + * Return a PDO instance. * * @return \PDO */ diff --git a/src/Symfony/Component/Security/Core/Tests/Util/SecureRandomTest.php b/src/Symfony/Component/Security/Core/Tests/Util/SecureRandomTest.php index 666af30d49..2e94cc14ba 100644 --- a/src/Symfony/Component/Security/Core/Tests/Util/SecureRandomTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Util/SecureRandomTest.php @@ -138,7 +138,7 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase */ public function testSerialCorrelation($secureRandom) { - $shift = rand(1, 5000); + $shift = mt_rand(1, 5000); $b = $this->getBitSequence($secureRandom, 20000); $Z = 0; diff --git a/src/Symfony/Component/Translation/Loader/JsonFileLoader.php b/src/Symfony/Component/Translation/Loader/JsonFileLoader.php index 09138835a6..81717f3d94 100644 --- a/src/Symfony/Component/Translation/Loader/JsonFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/JsonFileLoader.php @@ -20,7 +20,7 @@ use Symfony\Component\Config\Resource\FileResource; * * @author singles */ -class JsonFileLoader extends ArrayLoader implements LoaderInterface +class JsonFileLoader extends ArrayLoader { /** * {@inheritdoc} diff --git a/src/Symfony/Component/Translation/Tests/TranslatorTest.php b/src/Symfony/Component/Translation/Tests/TranslatorTest.php index 3ee9be019d..cb36183188 100644 --- a/src/Symfony/Component/Translation/Tests/TranslatorTest.php +++ b/src/Symfony/Component/Translation/Tests/TranslatorTest.php @@ -502,7 +502,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase public function testGetMessages($resources, $locale, $expected) { $locales = array_keys($resources); - $_locale = !is_null($locale) ? $locale : reset($locales); + $_locale = null !== $locale ? $locale : reset($locales); $locales = array_slice($locales, 0, array_search($_locale, $locales)); $translator = new Translator($_locale, new MessageSelector()); From 2f4280110d46158e86d4567255c4cf26e3409667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 2 Jul 2015 12:39:07 +0200 Subject: [PATCH 16/19] [Serializer] Fix ClassMetadata::sleep() --- .../Serializer/Mapping/ClassMetadata.php | 2 +- .../Tests/Mapping/AttributeMetadataTest.php | 10 ++++++++++ .../Tests/Mapping/ClassMetadataTest.php | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Mapping/ClassMetadata.php b/src/Symfony/Component/Serializer/Mapping/ClassMetadata.php index 3794a7451b..55ddf52a64 100644 --- a/src/Symfony/Component/Serializer/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Serializer/Mapping/ClassMetadata.php @@ -110,7 +110,7 @@ class ClassMetadata implements ClassMetadataInterface { return array( 'name', - 'attributes', + 'attributesMetadata', ); } } diff --git a/src/Symfony/Component/Serializer/Tests/Mapping/AttributeMetadataTest.php b/src/Symfony/Component/Serializer/Tests/Mapping/AttributeMetadataTest.php index f22746bc5d..4a32831cb6 100644 --- a/src/Symfony/Component/Serializer/Tests/Mapping/AttributeMetadataTest.php +++ b/src/Symfony/Component/Serializer/Tests/Mapping/AttributeMetadataTest.php @@ -54,4 +54,14 @@ class AttributeMetadataTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('a', 'b', 'c'), $attributeMetadata1->getGroups()); } + + public function testSerialize() + { + $attributeMetadata = new AttributeMetadata('attribute'); + $attributeMetadata->addGroup('a'); + $attributeMetadata->addGroup('b'); + + $serialized = serialize($attributeMetadata); + $this->assertEquals($attributeMetadata, unserialize($serialized)); + } } diff --git a/src/Symfony/Component/Serializer/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Serializer/Tests/Mapping/ClassMetadataTest.php index 90017580ac..629c17b788 100644 --- a/src/Symfony/Component/Serializer/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Serializer/Tests/Mapping/ClassMetadataTest.php @@ -62,4 +62,21 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('a1' => $ac1), $classMetadata2->getAttributesMetadata()); } + + public function testSerialize() + { + $classMetadata = new ClassMetadata('a'); + + $a1 = $this->getMock('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface'); + $a1->method('getName')->willReturn('b1'); + + $a2 = $this->getMock('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface'); + $a2->method('getName')->willReturn('b2'); + + $classMetadata->addAttributeMetadata($a1); + $classMetadata->addAttributeMetadata($a2); + + $serialized = serialize($classMetadata); + $this->assertEquals($classMetadata, unserialize($serialized)); + } } From eda5cb1c271ff7be919d8311a9032a6558436676 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 8 Jul 2015 18:59:03 +0100 Subject: [PATCH 17/19] [HttpFoundation] Add a test case to confirm a bug in session migration --- .../Session/Storage/NativeSessionStorageTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 851e6752b0..c8743aba94 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -119,6 +119,17 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase $this->assertEquals(11, $storage->getBag('attributes')->get('legs')); } + public function testSessionGlobalIsUpToDateAfterIdRegeneration() + { + $storage = $this->getStorage(); + $storage->start(); + $storage->getBag('attributes')->set('lucky', 7); + $storage->regenerate(); + $storage->getBag('attributes')->set('lucky', 42); + + $this->assertEquals(42, $_SESSION['_sf2_attributes']['lucky']); + } + public function testDefaultSessionCacheLimiter() { $this->iniSet('session.cache_limiter', 'nocache'); From 99b9c78b0034194d8ee27b9917e4d01fac8fb47f Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 8 Jul 2015 20:32:24 +0100 Subject: [PATCH 18/19] [HttpFoundation] Reload the session after regenerating its id --- .../Session/Storage/NativeSessionStorage.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index a5bdbe91d8..db705db87c 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -203,7 +203,13 @@ class NativeSessionStorage implements SessionStorageInterface $this->metadataBag->stampNew(); } - return session_regenerate_id($destroy); + $isRegenerated = session_regenerate_id($destroy); + + // The reference to $_SESSION in session bags is lost in PHP7 and we need to re-create it. + // @see https://bugs.php.net/bug.php?id=70013 + $this->loadSession(); + + return $isRegenerated; } /** From c4bf2e637c3947df90d6fa3e87dbcf144c730e90 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Thu, 9 Jul 2015 10:53:40 +0200 Subject: [PATCH 19/19] Added 'default' color --- .../Component/Console/Formatter/OutputFormatterStyle.php | 2 ++ .../Console/Tests/Formatter/OutputFormatterStyleTest.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index 48e9850725..0438d4bc03 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -29,6 +29,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface 'magenta' => 35, 'cyan' => 36, 'white' => 37, + 'default' => 39, ); private static $availableBackgroundColors = array( 'black' => 40, @@ -39,6 +40,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface 'magenta' => 45, 'cyan' => 46, 'white' => 47, + 'default' => 49, ); private static $availableOptions = array( 'bold' => 1, diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php index 6890a9b839..d0ebb27512 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php @@ -37,6 +37,9 @@ class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase $style->setForeground('blue'); $this->assertEquals("\033[34mfoo\033[0m", $style->apply('foo')); + $style->setForeground('default'); + $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo')); + $this->setExpectedException('InvalidArgumentException'); $style->setForeground('undefined-color'); } @@ -51,6 +54,9 @@ class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase $style->setBackground('yellow'); $this->assertEquals("\033[43mfoo\033[0m", $style->apply('foo')); + $style->setBackground('default'); + $this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo')); + $this->setExpectedException('InvalidArgumentException'); $style->setBackground('undefined-color'); }