From a78474360927c58bebb433c4c0a6dfac675995e4 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 11 Mar 2016 18:42:00 -0600 Subject: [PATCH 01/10] [Validator] Updating inaccurate docblock comment The formatValue() docblock refers to a $prettyDateTime argument, which does not exist. Instead, it should refer to the $format argument. --- src/Symfony/Component/Validator/ConstraintValidator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index f07a2d9fa3..3e4c5420da 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -69,9 +69,9 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface * This method returns the equivalent PHP tokens for most scalar types * (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped * in double quotes ("). Objects, arrays and resources are formatted as - * "object", "array" and "resource". If the parameter $prettyDateTime - * is set to true, {@link \DateTime} objects will be formatted as - * RFC-3339 dates ("Y-m-d H:i:s"). + * "object", "array" and "resource". If the $format bitmask contains + * the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted + * as RFC-3339 dates ("Y-m-d H:i:s"). * * Be careful when passing message parameters to a constraint violation * that (may) contain objects, arrays or resources. These parameters @@ -99,7 +99,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface } if (is_object($value)) { - if ($format & self::OBJECT_TO_STRING && method_exists($value, '__toString')) { + if (($format & self::OBJECT_TO_STRING) && method_exists($value, '__toString')) { return $value->__toString(); } From 7462fa59b1f93428db85171769a3f8dcc98f5020 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Mon, 14 Mar 2016 22:10:13 +0100 Subject: [PATCH 02/10] FrameworkBundle: Client: getContainer(): fixed phpdoc The kernel might be shut down and then the method will return null instead of a ContainerInterface object --- src/Symfony/Bundle/FrameworkBundle/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index 4f569131ad..6de49b3104 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -41,7 +41,7 @@ class Client extends BaseClient /** * Returns the container. * - * @return ContainerInterface + * @return ContainerInterface|null Returns null when the Kernel has been shutdown or not started yet */ public function getContainer() { From cfb3ea1a5fa931d0a5cf80f06c5e659a516bf3a8 Mon Sep 17 00:00:00 2001 From: Amine Matmati Date: Fri, 11 Mar 2016 23:15:57 -0600 Subject: [PATCH 03/10] [SecurityBundle][PHPDoc] Added method doumentation for SecurityFactoryInterface --- .../Factory/SecurityFactoryInterface.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SecurityFactoryInterface.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SecurityFactoryInterface.php index fce2f07580..2b3310c61a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SecurityFactoryInterface.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SecurityFactoryInterface.php @@ -21,6 +21,20 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; */ interface SecurityFactoryInterface { + /** + * Configures the container services required to use the authentication listener. + * + * @param ContainerBuilder $container + * @param string $id The unique id of the firewall + * @param array $config The options array for the listener + * @param string $userProvider The service id of the user provider + * @param string $defaultEntryPoint + * + * @return array containing three values: + * - the provider id + * - the listener id + * - the entry point id + */ public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint); /** @@ -31,6 +45,12 @@ interface SecurityFactoryInterface */ public function getPosition(); + /** + * Defines the configuration key used to reference the provider + * in the firewall configuration. + * + * @return string + */ public function getKey(); public function addConfiguration(NodeDefinition $builder); From 6b6073f68585415c050c8b6bf0b17efa10cd6cb7 Mon Sep 17 00:00:00 2001 From: Catalin Dan Date: Wed, 9 Mar 2016 16:43:58 +0200 Subject: [PATCH 04/10] [Form] Fix INT64 cast to float in IntegerType. --- .../DataTransformer/NumberToLocalizedStringTransformer.php | 6 +++++- .../NumberToLocalizedStringTransformerTest.php | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index 7cc3d5c805..acb75f2ca1 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -122,7 +122,11 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface $value = str_replace(',', $decSep, $value); } - $result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position); + if (!strstr($value, $decSep) && PHP_INT_SIZE === 8) { + $result = $formatter->parse($value, \NumberFormatter::TYPE_INT64, $position); + } else { + $result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position); + } if (intl_is_failure($formatter->getErrorCode())) { throw new TransformationFailedException($formatter->getErrorMessage()); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php index e829871ec3..ef9c9738cb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php @@ -433,4 +433,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase $transformer->reverseTransform("12\xc2\xa0345,678foo"); } + + public function testReverseTransformBigint() + { + $transformer = new NumberToLocalizedStringTransformer(null, true); + + $this->assertEquals(401657096594165125, (int) $transformer->reverseTransform((string) 401657096594165125)); + } } From 03c008cdbfa7c978fe76fc04b3077f1315b378d4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 15 Mar 2016 16:33:36 +0100 Subject: [PATCH 05/10] [Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers --- .../NumberToLocalizedStringTransformer.php | 10 +++++++--- .../NumberToLocalizedStringTransformerTest.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index acb75f2ca1..a18eb957b5 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -122,12 +122,16 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface $value = str_replace(',', $decSep, $value); } - if (!strstr($value, $decSep) && PHP_INT_SIZE === 8) { - $result = $formatter->parse($value, \NumberFormatter::TYPE_INT64, $position); + if (false !== strpos($value, $decSep)) { + $type = \NumberFormatter::TYPE_DOUBLE; } else { - $result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position); + $type = PHP_INT_SIZE === 8 + ? \NumberFormatter::TYPE_INT64 + : \NumberFormatter::TYPE_INT32; } + $result = $formatter->parse($value, $type, $position); + if (intl_is_failure($formatter->getErrorCode())) { throw new TransformationFailedException($formatter->getErrorMessage()); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php index ef9c9738cb..87cdf964c8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php @@ -438,6 +438,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase { $transformer = new NumberToLocalizedStringTransformer(null, true); - $this->assertEquals(401657096594165125, (int) $transformer->reverseTransform((string) 401657096594165125)); + $this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1))); } } From 970b9568b17ecc957ba82553e7395c2a53739197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20Fr=C3=A9cinaux?= Date: Tue, 15 Mar 2016 12:47:29 +0100 Subject: [PATCH 06/10] bug #18161 [Translation] Add support for fuzzy tags in PoFileLoader The traditional gettext tools usually try to find similar strings when updating translations. This results in some strings having a translation but being marked as "fuzzy", even if the translation is not correct. The expected result when a string is marked as fuzzy is that it should not be used by the translation system. Using symfony, though, the translations were used, which could result in "funny" messages being displayed in the interface despite being often completely out of context. This commit discards messages in .po files that have a '#, fuzzy' flag. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | 18161 | License | MIT | Doc PR | - --- .../Component/Translation/Loader/PoFileLoader.php | 12 ++++++++++-- .../Translation/Tests/Loader/PoFileLoaderTest.php | 12 ++++++++++++ .../Translation/Tests/fixtures/fuzzy-translations.po | 10 ++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Translation/Tests/fixtures/fuzzy-translations.po diff --git a/src/Symfony/Component/Translation/Loader/PoFileLoader.php b/src/Symfony/Component/Translation/Loader/PoFileLoader.php index b5d12e9821..29e898cc47 100644 --- a/src/Symfony/Component/Translation/Loader/PoFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PoFileLoader.php @@ -108,14 +108,20 @@ class PoFileLoader extends ArrayLoader $messages = array(); $item = $defaults; + $flags = array(); while ($line = fgets($stream)) { $line = trim($line); if ($line === '') { // Whitespace indicated current item is done - $this->addMessage($messages, $item); + if (!in_array('fuzzy', $flags)) { + $this->addMessage($messages, $item); + } $item = $defaults; + $flags = array(); + } elseif (substr($line, 0, 2) === '#,') { + $flags = array_map('trim', explode(',', substr($line, 2))); } elseif (substr($line, 0, 7) === 'msgid "') { // We start a new msg so save previous // TODO: this fails when comments or contexts are added @@ -141,7 +147,9 @@ class PoFileLoader extends ArrayLoader } } // save last item - $this->addMessage($messages, $item); + if (!in_array('fuzzy', $flags)) { + $this->addMessage($messages, $item); + } fclose($stream); return $messages; diff --git a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php index 87090eb736..5d340c766f 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php @@ -93,4 +93,16 @@ class PoFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals('escaped "bar"', $messages['escaped "foo"']); $this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']); } + + public function testSkipFuzzyTranslations() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/fuzzy-translations.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $messages = $catalogue->all('domain1'); + $this->assertArrayHasKey('foo1', $messages); + $this->assertArrayNotHasKey('foo2', $messages); + $this->assertArrayHasKey('foo3', $messages); + } } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/fuzzy-translations.po b/src/Symfony/Component/Translation/Tests/fixtures/fuzzy-translations.po new file mode 100644 index 0000000000..04d4047aa4 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/fixtures/fuzzy-translations.po @@ -0,0 +1,10 @@ +#, php-format +msgid "foo1" +msgstr "bar1" + +#, fuzzy, php-format +msgid "foo2" +msgstr "fuzzy bar2" + +msgid "foo3" +msgstr "bar3" From c722e35fb3749246b54990818628278ab6c6db23 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 16 Mar 2016 14:40:51 +0100 Subject: [PATCH 07/10] [travis] Run real php subprocesses on hhvm for Process component tests --- .travis.yml | 1 + src/Symfony/Component/Process/Tests/ProcessTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 23fe0109ee..22d38d3e11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: env: global: - MIN_PHP=5.3.3 + - SYMFONY_PROCESS_PHP_TEST_BINARY=~/.phpenv/versions/5.6/bin/php matrix: include: diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 14daf2c286..c33e0837b9 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -30,7 +30,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase public static function setUpBeforeClass() { $phpBin = new PhpExecutableFinder(); - self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find(); + self::$phpBin = getenv('SYMFONY_PROCESS_PHP_TEST_BINARY') ?: ('phpdbg' === PHP_SAPI ? 'php' : $phpBin->find()); if ('\\' !== DIRECTORY_SEPARATOR) { // exec is mandatory to deal with sending a signal to the process // see https://github.com/symfony/symfony/issues/5030 about prepending From 165755a01fc5978d8ae7e4d0d8bcbcd1b43be420 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 15 Mar 2016 18:45:16 +0100 Subject: [PATCH 08/10] [Validator] Test DNS Email constraints using checkdnsrr() mock --- phpunit | 4 +- phpunit.xml.dist | 2 +- .../Component/HttpKernel/phpunit.xml.dist | 2 +- .../Tests/Constraints/EmailValidatorTest.php | 39 +++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/phpunit b/phpunit index 9cf03f071e..9806b0053f 100755 --- a/phpunit +++ b/phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id-Version: 2015-11-28 09:05 UTC +// Cache-Id-Version: 2016-03-16 15:36 UTC use Symfony\Component\Process\ProcessUtils; @@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ $zip->close(); chdir("phpunit-$PHPUNIT_VERSION"); passthru("$COMPOSER remove --no-update symfony/yaml"); - passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\""); + passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\""); passthru("$COMPOSER install --prefer-dist --no-progress --ansi"); file_put_contents('phpunit', << - Symfony\Component\HttpFoundation + Symfony\Component\HttpFoundation diff --git a/src/Symfony/Component/HttpKernel/phpunit.xml.dist b/src/Symfony/Component/HttpKernel/phpunit.xml.dist index 17c48935c7..b29969b36f 100644 --- a/src/Symfony/Component/HttpKernel/phpunit.xml.dist +++ b/src/Symfony/Component/HttpKernel/phpunit.xml.dist @@ -30,7 +30,7 @@ - Symfony\Component\HttpFoundation + Symfony\Component\HttpFoundation diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index e291124f29..10d17b5c68 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -11,9 +11,13 @@ namespace Symfony\Component\Validator\Tests\Constraints; +use Symfony\Bridge\PhpUnit\DnsMock; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\EmailValidator; +/** + * @group dns-sensitive + */ class EmailValidatorTest extends AbstractConstraintValidatorTest { protected function createValidator() @@ -86,4 +90,39 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest array('example@localhost'), ); } + + /** + * @dataProvider getDnsChecks + */ + public function testDnsChecks($type, $violation) + { + DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? false : $type)))); + + $constraint = new Email(array( + 'message' => 'myMessage', + 'MX' === $type ? 'checkMX' : 'checkHost' => true, + )); + + $this->validator->validate('foo@example.com', $constraint); + + if (!$violation) { + $this->assertNoViolation(); + } else { + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"foo@example.com"') + ->assertRaised(); + } + } + + public function getDnsChecks() + { + return array( + array('MX', false), + array('MX', true), + array('A', false), + array('A', true), + array('AAAA', false), + array('AAAA', true), + ); + } } From 9ad67caea501f34ab65b38573d5dcec7ba9fd371 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 16 Mar 2016 15:32:55 +0100 Subject: [PATCH 09/10] Improved the PHPdoc of FileSystem::copy() --- src/Symfony/Component/Filesystem/Filesystem.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index d800bd72fc..dcef5c64ae 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -23,17 +23,17 @@ class Filesystem /** * Copies a file. * - * This method only copies the file if the origin file is newer than the target file. + * If the target file is older than the origin file, it's always overwritten. + * If the target file is newer, it is overwritten only when the + * $overwriteNewerFiles option is set to true. * - * By default, if the target already exists, it is not overridden. - * - * @param string $originFile The original filename - * @param string $targetFile The target filename - * @param bool $override Whether to override an existing file or not + * @param string $originFile The original filename + * @param string $targetFile The target filename + * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten * * @throws IOException When copy fails */ - public function copy($originFile, $targetFile, $override = false) + public function copy($originFile, $targetFile, $overwriteNewerFiles = false) { if (stream_is_local($originFile) && !is_file($originFile)) { throw new IOException(sprintf('Failed to copy %s because file not exists', $originFile)); @@ -42,7 +42,7 @@ class Filesystem $this->mkdir(dirname($targetFile)); $doCopy = true; - if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) { + if (!$overwriteNewerFiles && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) { $doCopy = filemtime($originFile) > filemtime($targetFile); } From a4b42d1fbddaa12d57ae99a8c95dbef05647aad9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 16 Mar 2016 15:58:21 +0100 Subject: [PATCH 10/10] [Validator] Test DNS Url constraints using checkdnsrr() mock --- .../Tests/Constraints/UrlValidatorTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index ab22876a1f..fab7cf1867 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -11,10 +11,14 @@ namespace Symfony\Component\Validator\Tests\Constraints; +use Symfony\Bridge\PhpUnit\DnsMock; use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\UrlValidator; use Symfony\Component\Validator\Validation; +/** + * @group dns-sensitive + */ class UrlValidatorTest extends AbstractConstraintValidatorTest { protected function getApiVersion() @@ -187,6 +191,34 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('git://[::1]/'), ); } + + /** + * @dataProvider getCheckDns + */ + public function testCheckDns($violation) + { + DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? '' : 'A')))); + + $constraint = new Url(array( + 'checkDNS' => true, + 'dnsMessage' => 'myMessage', + )); + + $this->validator->validate('http://example.com', $constraint); + + if (!$violation) { + $this->assertNoViolation(); + } else { + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"example.com"') + ->assertRaised(); + } + } + + public function getCheckDns() + { + return array(array(true), array(false)); + } } class EmailProvider