Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  Improved the PHPdoc of FileSystem::copy()
  [Validator] Test DNS Email constraints using checkdnsrr() mock
  [travis] Run real php subprocesses on hhvm for Process component tests
  bug symfony#18161 [Translation] Add support for fuzzy tags in PoFileLoader
  [Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers
  [Form] Fix INT64 cast to float in IntegerType.
  [SecurityBundle][PHPDoc] Added method doumentation for SecurityFactoryInterface
  FrameworkBundle: Client: getContainer(): fixed phpdoc
  [Validator] Updating inaccurate docblock comment

Conflicts:
	.travis.yml
	src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php
  • Loading branch information
nicolas-grekas committed Mar 16, 2016
2 parents 67e9ba0 + 56624e6 commit c7686a3
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 26 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ addons:
env:
global:
- MIN_PHP=5.3.9
- SYMFONY_PROCESS_PHP_TEST_BINARY=~/.phpenv/versions/5.6/bin/php

matrix:
include:
Expand Down
4 changes: 2 additions & 2 deletions phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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', <<<EOPHP
<?php
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi
/**
* Returns the container.
*
* @return ContainerInterface
* @return ContainerInterface|null Returns null when the Kernel has been shutdown or not started yet
*/
public function getContainer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
*/
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);

/**
Expand All @@ -31,6 +45,12 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
*/
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);
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ 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 FileNotFoundException When originFile doesn't exist
* @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 FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
Expand All @@ -44,7 +44,7 @@ public function copy($originFile, $targetFile, $override = false)
$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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ public function reverseTransform($value)
$value = str_replace(',', $decSep, $value);
}

$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
if (false !== strpos($value, $decSep)) {
$type = \NumberFormatter::TYPE_DOUBLE;
} else {
$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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,11 @@ public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()

$transformer->reverseTransform("12\xc2\xa0345,678foo");
}

public function testReverseTransformBigint()
{
$transformer = new NumberToLocalizedStringTransformer(null, true);

$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
namespace Symfony\Component\HttpKernel\Tests\HttpCache;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategy;
use Symfony\Component\HttpKernel\HttpCache\ResponseCacheStrategy;

class EsiResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase
class ResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase
{
public function testMinimumSharedMaxAgeWins()
{
$cacheStrategy = new EsiResponseCacheStrategy();
$cacheStrategy = new ResponseCacheStrategy();

$response1 = new Response();
$response1->setSharedMaxAge(60);
Expand All @@ -41,7 +41,7 @@ public function testMinimumSharedMaxAgeWins()

public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest()
{
$cacheStrategy = new EsiResponseCacheStrategy();
$cacheStrategy = new ResponseCacheStrategy();

$response1 = new Response();
$response1->setSharedMaxAge(60);
Expand All @@ -59,7 +59,7 @@ public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest()

public function testSharedMaxAgeNotSetIfNotSetInMasterRequest()
{
$cacheStrategy = new EsiResponseCacheStrategy();
$cacheStrategy = new ResponseCacheStrategy();

$response1 = new Response();
$response1->setSharedMaxAge(60);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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
Expand Down
12 changes: 10 additions & 2 deletions src/Symfony/Component/Translation/Loader/PoFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ private function parse($resource)

$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
Expand All @@ -141,7 +147,9 @@ private function parse($resource)
}
}
// save last item
$this->addMessage($messages, $item);
if (!in_array('fuzzy', $flags)) {
$this->addMessage($messages, $item);
}
fclose($stream);

return $messages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ public function testEscapedIdPlurals()
$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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#, php-format
msgid "foo1"
msgstr "bar1"

#, fuzzy, php-format
msgid "foo2"
msgstr "fuzzy bar2"

msgid "foo3"
msgstr "bar3"
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ protected function formatTypeOf($value)
* 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
Expand Down Expand Up @@ -159,7 +159,7 @@ protected function formatValue($value, $format = 0)
}

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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Bridge\PhpUnit\DnsMock;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\EmailValidator;
use Symfony\Component\Validator\Validation;

/**
* @group dns-sensitive
*/
class EmailValidatorTest extends AbstractConstraintValidatorTest
{
protected function getApiVersion()
Expand Down Expand Up @@ -103,4 +107,40 @@ public function testStrict()

$this->assertNoViolation();
}

/**
* @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('[email protected]', $constraint);

if (!$violation) {
$this->assertNoViolation();
} else {
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"[email protected]"')
->setCode($violation)
->assertRaised();
}
}

public function getDnsChecks()
{
return array(
array('MX', false),
array('MX', Email::MX_CHECK_FAILED_ERROR),
array('A', false),
array('A', Email::HOST_CHECK_FAILED_ERROR),
array('AAAA', false),
array('AAAA', Email::HOST_CHECK_FAILED_ERROR),
);
}
}

0 comments on commit c7686a3

Please sign in to comment.