Merge branch '3.2'
* 3.2: move provider after test update dataProvider function name cast substr result to string and remove empty function use rename dataset provider Add a test to prevent future regressions Switch to `empty` native function to check emptiness remove non relevant test case Switch to `is_string` native method Remove unnecessary parentheses Add a test case to prevent future regressions Move empty condition in return statement Use LF line separator fix coding standard to comply with fabbot Remove malformed EmailValidatorTest + Update UrlValidator test Add empty check on host in other methods + add unit tests [Validator] Allow checkMX() to return false when $host is empty [DI] Prevent AutowirePass from triggering irrelevant deprecations [DI] Fix the xml schema [Translation] avoid creating cache files for fallback locales.
This commit is contained in:
commit
12bb392a39
@ -355,9 +355,23 @@ class AutowirePass extends AbstractRecursivePass
|
||||
unset($this->ambiguousServiceTypes[$type]);
|
||||
}
|
||||
|
||||
if ($deprecated = $definition->isDeprecated()) {
|
||||
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
|
||||
return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line);
|
||||
});
|
||||
}
|
||||
|
||||
$e = null;
|
||||
|
||||
try {
|
||||
if (!$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
if ($deprecated) {
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reflectionClass->getInterfaces() as $reflectionInterface) {
|
||||
$this->set($reflectionInterface->name, $id);
|
||||
|
@ -197,8 +197,8 @@
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="property" mixed="true">
|
||||
<xsd:choice minOccurs="0" maxOccurs="1">
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="property" type="property" maxOccurs="unbounded" />
|
||||
<xsd:element name="service" type="service" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="type" type="argument_type" />
|
||||
@ -210,8 +210,8 @@
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="argument" mixed="true">
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
|
||||
<xsd:element name="service" type="service" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="type" type="argument_type" />
|
||||
@ -223,10 +223,9 @@
|
||||
<xsd:attribute name="method" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="call" mixed="true">
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="service" type="service" />
|
||||
<xsd:complexType name="call">
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="method" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
@ -595,6 +595,17 @@ class AutowirePassTest extends TestCase
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotTriggerDeprecations()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
|
||||
$container->register('foo', __NAMESPACE__.'\Foo');
|
||||
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
public function testEmptyStringIsKept()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
@trigger_error('deprecated', E_USER_DEPRECATED);
|
||||
|
||||
class DeprecatedClass
|
||||
{
|
||||
}
|
@ -149,6 +149,17 @@ class TranslatorCacheTest extends TestCase
|
||||
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
|
||||
}
|
||||
|
||||
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
|
||||
{
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
$translator->setFallbackLocales(array('b'));
|
||||
$translator->trans('bar');
|
||||
|
||||
$cachedFiles = glob($this->tmpDir.'/*.php');
|
||||
|
||||
$this->assertCount(1, $cachedFiles);
|
||||
}
|
||||
|
||||
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
|
||||
{
|
||||
/*
|
||||
|
@ -386,7 +386,7 @@ EOF
|
||||
|
||||
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
||||
if (!isset($this->catalogues[$fallback])) {
|
||||
$this->loadCatalogue($fallback);
|
||||
$this->initializeCatalogue($fallback);
|
||||
}
|
||||
|
||||
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
||||
|
@ -87,7 +87,7 @@ class EmailValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
$host = substr($value, strrpos($value, '@') + 1);
|
||||
$host = (string) substr($value, strrpos($value, '@') + 1);
|
||||
|
||||
// Check for host DNS resource records
|
||||
if ($constraint->checkMX) {
|
||||
@ -118,7 +118,7 @@ class EmailValidator extends ConstraintValidator
|
||||
*/
|
||||
private function checkMX($host)
|
||||
{
|
||||
return checkdnsrr($host, 'MX');
|
||||
return '' !== $host && checkdnsrr($host, 'MX');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,6 +130,6 @@ class EmailValidator extends ConstraintValidator
|
||||
*/
|
||||
private function checkHost($host)
|
||||
{
|
||||
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
|
||||
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class UrlValidator extends ConstraintValidator
|
||||
if ($constraint->checkDNS) {
|
||||
$host = parse_url($value, PHP_URL_HOST);
|
||||
|
||||
if (!checkdnsrr($host, 'ANY')) {
|
||||
if (!is_string($host) || !checkdnsrr($host, 'ANY')) {
|
||||
$this->context->buildViolation($constraint->dnsMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($host))
|
||||
->setCode(Url::INVALID_URL_ERROR)
|
||||
|
@ -229,4 +229,32 @@ class EmailValidatorTest extends ConstraintValidatorTestCase
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCheckTypes
|
||||
*/
|
||||
public function testEmptyHostIsNotValid($checkType, $violation)
|
||||
{
|
||||
$this->validator->validate(
|
||||
'foo@bar.fr@',
|
||||
new Email(array(
|
||||
'message' => 'myMessage',
|
||||
$checkType => true,
|
||||
))
|
||||
);
|
||||
|
||||
$this
|
||||
->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"foo@bar.fr@"')
|
||||
->setCode($violation)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function provideCheckTypes()
|
||||
{
|
||||
return array(
|
||||
array('checkMX', Email::MX_CHECK_FAILED_ERROR),
|
||||
array('checkHost', Email::HOST_CHECK_FAILED_ERROR),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +167,7 @@ class UrlValidatorTest extends ConstraintValidatorTestCase
|
||||
array('http://example.com/exploit.html?<script>alert(1);</script>'),
|
||||
array('http://example.com/exploit.html?hel lo'),
|
||||
array('http://example.com/exploit.html?not_a%hex'),
|
||||
array('http://'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user