8000 Merge branch '2.3' into 2.7 · dunglas/symfony@c7686a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7686a3

Browse files
Merge branch '2.3' into 2.7
* 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
2 parents 67e9ba0 + 56624e6 commit c7686a3
10000

File tree

16 files changed

+132
-26
lines changed

16 files changed

+132
-26
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ addons:
1313
env:
1414
global:
1515
- MIN_PHP=5.3.9
16+
- SYMFONY_PROCESS_PHP_TEST_BINARY=~/.phpenv/versions/5.6/bin/php
1617

1718
matrix:
1819
include:

phpunit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// Please update when phpunit needs to be reinstalled with fresh deps:
14-
// Cache-Id-Version: 2015-11-28 09:05 UTC
14+
// Cache-Id-Version: 2016-03-16 15:36 UTC
1515

1616
use Symfony\Component\Process\ProcessUtils;
1717

@@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
5252
$zip->close();
5353
chdir("phpunit-$PHPUNIT_VERSION");
5454
passthru("$COMPOSER remove --no-update symfony/yaml");
55-
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
55+
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\"");
5656
passthru("$COMPOSER install --prefer-dist --no-progress --ansi");
5757
file_put_contents('phpunit', <<<EOPHP
5858
<?php

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
5353
<arguments>
5454
<array>
55-
<element><string>Symfony\Component\HttpFoundation</string></element>
55+
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
5656
</array>
5757
</arguments>
5858
</listener>

src/Symfony/Bundle/FrameworkBundle/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi
4242
/**
4343
* Returns the container.
4444
*
45-
* @return ContainerInterface
45+
* @return ContainerInterface|null Returns null when the Kernel has been shutdown or not started yet
4646
*/
4747
public function getContainer()
4848
{

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/SecurityFactoryInterface.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
*/
2222
interface SecurityFactoryInterface
2323
{
24+
/**
25+
* Configures the container services required to use the authentication listener.
26+
*
27+
* @param ContainerBuilder $container
28+
* @param string $id The unique id of the firewall
29+
* @param array $config The options array for the listener
30+
* @param string $userProvider The service id of the user provider
31+
* @param string $defaultEntryPoint
32+
*
33+
* @return array containing three values:
34+
* - the provider id
35+
* - the listener id
36+
* - the entry point id
37+
*/
2438
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint);
2539

2640
/**
@@ -31,6 +45,12 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
3145
*/
3246
public function getPosition();
3347

48+
/**
49+
* Defines the configuration key used to reference the provider
50+
* in the firewall configuration.
51+
*
52+
* @return string
53+
*/
3454
public function getKey();
3555

3656
public function addConfiguration(NodeDefinition $builder);

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ class Filesystem
2424
/**
2525
* Copies a file.
2626
*
27-
* This method only copies the file if the origin file is newer than the target file.
27+
* If the target file is older than the origin file, it's always overwritten.
28+
* If the target file is newer, it is overwritten only when the
29+
* $overwriteNewerFiles option is set to true.
2830
*
29-
* By default, if the target already exists, it is not overridden.
30-
*
31-
* @param string $originFile The original filename
32-
* @param string $targetFile The target filename
33-
* @param bool $override Whether to override an existing file or not
31+
* @param string $originFile The original filename
32+
* @param string $targetFile The target filename
33+
* @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten
3434
*
3535
* @throws FileNotFoundException When originFile doesn't exist
3636
* @throws IOException When copy fails
3737
*/
38-
public function copy($originFile, $targetFile, $override = false)
38+
public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
3939
{
4040
if (stream_is_local($originFile) && !is_file($originFile)) {
4141
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
@@ -44,7 +44,7 @@ public function copy($originFile, $targetFile, $override = false)
4444
$this->mkdir(dirname($targetFile));
4545

4646
$doCopy = true;
47-
if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
47+
if (!$overwriteNewerFiles && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
4848
$doCopy = filemtime($originFile) > filemtime($targetFile);
4949
}
5050

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,15 @@ public function reverseTransform($value)
187187
$value = str_replace(',', $decSep, $value);
188188
}
189189

190-
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
190+
if (false !== strpos($value, $decSep)) {
191+
$type = \NumberFormatter::TYPE_DOUBLE;
192+
} else {
193+
$type = PHP_INT_SIZE === 8
194+
? \NumberFormatter::TYPE_INT64
195+
: \NumberFormatter::TYPE_INT32;
196+
}
197+
198+
$result = $formatter->parse($value, $type, $position);
191199

192200
if (intl_is_failure($formatter->getErrorCode())) {
193201
throw new TransformationFailedException($formatter->getErrorMessage());

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,11 @@ public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
641641

642642
$transformer->reverseTransform("12\xc2\xa0345,678foo");
643643
}
644+
645+
public function testReverseTransformBigint()
646+
{
647+
$transformer = new NumberToLocalizedStringTransformer(null, true);
648+
649+
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
650+
}
644651
}

src/Symfony/Component/HttpKernel/Tests/HttpCache/ResponseCacheStrategyTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
namespace Symfony\Component\HttpKernel\Tests\HttpCache;
1717

1818
use Symfony\Component\HttpFoundation\Response;
19-
use Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategy;
19+
use Symfony\Component\HttpKernel\HttpCache\ResponseCacheStrategy;
2020

21-
class EsiResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase
21+
class ResponseCacheStrategyTest extends \PHPUnit_Framework_TestCase
2222
{
2323
public function testMinimumSharedMaxAgeWins()
2424
{
25-
$cacheStrategy = new EsiResponseCacheStrategy();
25+
$cacheStrategy = new ResponseCacheStrategy();
2626

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

4242
public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest()
4343
{
44-
$cacheStrategy = new EsiResponseCacheStrategy();
44+
$cacheStrategy = new ResponseCacheStrategy();
4545

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

6060
public function testSharedMaxAgeNotSetIfNotSetInMasterRequest()
6161
{
62-
$cacheStrategy = new EsiResponseCacheStrategy();
62+
$cacheStrategy = new ResponseCacheStrategy();
6363

6464
$response1 = new Response();
6565
$response1->setSharedMaxAge(60);

src/Symfony/Component/HttpKernel/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
3131
<arguments>
3232
<array>
33-
<element><string>Symfony\Component\HttpFoundation</string></element>
33+
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
3434
</array>
3535
</arguments>
3636
</listener>

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
3131
public static function setUpBeforeClass()
3232
{
3333
$phpBin = new PhpExecutableFinder();
34-
self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find();
34+
self::$phpBin = getenv('SYMFONY_PROCESS_PHP_TEST_BINARY') ?: ('phpdbg' === PHP_SAPI ? 'php' : $phpBin->find());
3535
if ('\\' !== DIRECTORY_SEPARATOR) {
3636
// exec is mandatory to deal with sending a signal to the process
3737
// see https://github.com/symfony/symfony/issues/5030 about prepending

src/Symfony/Component/Translation/Loader/PoFileLoader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,20 @@ private function parse($resource)
108108

109109
$messages = array();
110110
$item = $defaults;
111+
$flags = array();
111112

112113
while ($line = fgets($stream)) {
113114
$line = trim($line);
114115

115116
if ($line === '') {
116117
// Whitespace indicated current item is done
117-
$this->addMessage($messages, $item);
118+
if (!in_array('fuzzy', $flags)) {
119+
$this->addMessage($messages, $item);
120+
}
118121
$item = $defaults;
122+
$flags = array();
123+
} elseif (substr($line, 0, 2) === '#,') {
124+
$flags = array_map('trim', explode(',', substr($line, 2)));
119125
} elseif (substr($line, 0, 7) === 'msgid "') {
120126
// We start a new msg so save previous
121127
// TODO: this fails when comments or contexts are added
@@ -141,7 +147,9 @@ private function parse($resource)
141147
}
142148
}
143149
// save last item
144-
$this->addMessage($messages, $item);
150+
if (!in_array('fuzzy', $flags)) {
151+
$this->addMessage($messages, $item);
152+
}
145153
fclose($stream);
146154

147155
return $messages;

src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@ public function testEscapedIdPlurals()
9393
$this->assertEquals('escaped "bar"', $messages['escaped "foo"']);
9494
$this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']);
9595
}
96+
97+
public function testSkipFuzzyTranslations()
98+
{
99+
$loader = new PoFileLoader();
100+
$resource = __DIR__.'/../fixtures/fuzzy-translations.po';
101+
$catalogue = $loader->load($resource, 'en', 'domain1');
102+
103+
$messages = $catalogue->all('domain1');
104+
$this->assertArrayHasKey('foo1', $messages);
105+
$this->assertArrayNotHasKey('foo2', $messages);
106+
$this->assertArrayHasKey('foo3', $messages);
107+
}
96108
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#, php-format
2+
msgid "foo1"
3+
msgstr "bar1"
4+
5+
#, fuzzy, php-format
6+
msgid "foo2"
7+
msgstr "fuzzy bar2"
8+
9+
msgid "foo3"
10+
msgstr "bar3"

src/Symfony/Component/Validator/ConstraintValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ protected function formatTypeOf($value)
118118
* This method returns the equivalent PHP tokens for most scalar types
119119
* (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped
120120
* in double quotes ("). Objects, arrays and resources are formatted as
121-
* "object", "array" and "resource". If the parameter $prettyDateTime
122-
* is set to true, {@link \DateTime} objects will be formatted as
123-
* RFC-3339 dates ("Y-m-d H:i:s").
121+
* "object", "array" and "resource". If the $format bitmask contains
122+
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
123+
* as RFC-3339 dates ("Y-m-d H:i:s").
124124
*
125125
* Be careful when passing message parameters to a constraint violation
126126
* that (may) contain objects, arrays or resources. These parameters
@@ -159,7 +159,7 @@ protected function formatValue($value, $format = 0)
159159
}
160160

161161
if (is_object($value)) {
162-
if ($format & self::OBJECT_TO_STRING && method_exists($value, '__toString')) {
162+
if (($format & self::OBJECT_TO_STRING) && method_exists($value, '__toString')) {
163163
return $value->__toString();
164164
}
165165

src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\DnsMock;
1415
use Symfony\Component\Validator\Constraints\Email;
1516
use Symfony\Component\Validator\Constraints\EmailValidator;
1617
use Symfony\Component\Validator\Validation;
1718

19+
/**
20+
* @group dns-sensitive
21+
*/
1822
class EmailValidatorTest extends AbstractConstraintValidatorTest
1923
{
2024
protected function getApiVersion()
@@ -103,4 +107,40 @@ public function testStrict()
103107

104108
$this->assertNoViolation();
105109
}
110+
111+
/**
112+
* @dataProvider getDnsChecks
113+
*/
114+
public function testDnsChecks($type, $violation)
115+
{
116+
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? false : $type))));
117+
118+
$constraint = new Email(array(
119+
'message' => 'myMessage',
120+
'MX' === $type ? 'checkMX' : 'checkHost' => true,
121+
));
122+
123+
$this->validator->validate('foo@example.com', $constraint);
124+
125+
if (!$violation) {
126+
$this->assertNoViolation();
127+
} else {
128+
$this->buildViolation('myMessage')
129+
->setParameter('{{ value }}', '"foo@example.com"')
130+
->setCode($violation)
131+
->assertRaised();
132+
}
133+
}
134+
135+
public function getDnsChecks()
136+
{
137+
return array(
138+
array('MX', false),
139+
array('MX', Email::MX_CHECK_FAILED_ERROR),
140+
array('A', false),
141+
array('A', Email::HOST_CHECK_FAILED_ERROR),
142+
array('AAAA', false),
143+
array('AAAA', Email::HOST_CHECK_FAILED_ERROR),
144+
);
145+
}
106146
}

0 commit comments

Comments
 (0)
0