8000 Merge branch '3.2' · Nek-/symfony@12bb392 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12bb392

Browse files
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.
2 parents 457174d + 32f264f commit 12bb392

File tree

10 files changed

+97
-15
lines changed

10 files changed

+97
-15
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,22 @@ private function populateAvailableType($id, Definition $definition)
355355
unset($this->ambiguousServiceTypes[$type]);
356356
}
357357

358-
if (!$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
359-
return;
358+
if ($deprecated = $definition->isDeprecated()) {
359+
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
360+
return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line);
361+
});
362+
}
363+
364+
$e = null;
365+
366+
try {
367+
if (!$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
368+
return;
369+
}
370+
} finally {
371+
if ($deprecated) {
372+
restore_error_handler();
373+
}
360374
}
361375

362376
foreach ($reflectionClass->getInterfaces() as $reflectionInterface) {

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@
197197
</xsd:complexType>
198198

199199
<xsd:complexType name="property" mixed="true">
200-
<xsd:choice minOccurs="0" maxOccurs="1">
201-
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
200+
<xsd:choice minOccurs="0">
201+
<xsd:element name="property" type="property" maxOccurs="unbounded" />
202202
<xsd:element name="service" type="service" />
203203
</xsd:choice>
204204
<xsd:attribute name="type" type="argument_type" />
@@ -210,8 +210,8 @@
210210
</xsd:complexType>
211211

212212
<xsd:complexType name="argument" mixed="true">
213-
<xsd:choice maxOccurs="unbounded">
214-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
213+
<xsd:choice minOccurs="0">
214+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
215215
<xsd:element name="service" type="service" />
216216
</xsd:choice>
217217
<xsd:attribute name="type" type="argument_type" />
@@ -223,10 +223,9 @@
223223
<xsd:attribute name="method" type="xsd:string" />
224224
</xsd:complexType>
225225

226-
<xsd:complexType name="call" mixed="true">
227-
<xsd:choice maxOccurs="unbounded">
228-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
229-
<xsd:element name="service" type="service" />
226+
<xsd:complexType name="call">
227+
<xsd:choice minOccurs="0">
228+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
230229
</xsd:choice>
231230
<xsd:attribute name="method" type="xsd:string" />
232231
</xsd:complexType>

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,17 @@ public function testSetterInjectionCollisionThrowsException()
595595
$pass->process($container);
596596
}
597597

598+
public function testProcessDoesNotTriggerDeprecations()
599+
{
600+
$container = new ContainerBuilder();
601+
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
602+
$container->register('foo', __NAMESPACE__.'\Foo');
603+
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
604+
605+
$pass = new AutowirePass();
606+
$pass->process($container);
607+
}
608+
598609
public function testEmptyStringIsKept()
599610
{
600611
$container = new ContainerBuilder();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
@trigger_error('deprecated', E_USER_DEPRECATED);
15+
16+
class DeprecatedClass
17+
{
18+
}

src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCac
149149
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
150150
}
151151

152+
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
153+
{
154+
$translator = new Translator('a', null, $this->tmpDir);
155+
$translator->setFallbackLocales(array('b'));
156+
$translator->trans('bar');
157+
158+
$cachedFiles = glob($this->tmpDir.'/*.php');
159+
160+
$this->assertCount(1, $cachedFiles);
161+
}
162+
152163
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
153164
{
154165
/*

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private function loadFallbackCatalogues($locale)
386386

387387
foreach ($this->computeFallbackLocales($locale) as $fallback) {
388388
if (!isset($this->catalogues[$fallback])) {
389-
$this->loadCatalogue($fallback);
389+
$this->initializeCatalogue($fallback);
390390
}
391391

392392
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function validate($value, Constraint $constraint)
8787
return;
8888
}
8989

90-
$host = substr($value, strrpos($value, '@') + 1);
90+
$host = (string) substr($value, strrpos($value, '@') + 1);
9191

9292
// Check for host DNS resource records
9393
if ($constraint->checkMX) {
@@ -118,7 +118,7 @@ public function validate($value, Constraint $constraint)
118118
*/
119119
private function checkMX($host)
120120
{
121-
return checkdnsrr($host, 'MX');
121+
return '' !== $host && checkdnsrr($host, 'MX');
122122
}
123123

124124
/**
@@ -130,6 +130,6 @@ private function checkMX($host)
130130
*/
131131
private function checkHost($host)
132132
{
133-
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
133+
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
134134
}
135135
}

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function validate($value, Constraint $constraint)
7474
if ($constraint->checkDNS) {
7575
$host = parse_url($value, PHP_URL_HOST);
7676

77-
if (!checkdnsrr($host, 'ANY')) {
77+
if (!is_string($host) || !checkdnsrr($host, 'ANY')) {
7878
$this->context->buildViolation($constraint->dnsMessage)
7979
->setParameter('{{ value }}', $this->formatValue($host))
8080
->setCode(Url::INVALID_URL_ERROR)

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,32 @@ public function testHostnameIsProperlyParsed()
229229

230230
$this->assertNoViolation();
231231
}
232+
233+
/**
234+
* @dataProvider provideCheckTypes
235+
*/
236+
public function testEmptyHostIsNotValid($checkType, $violation)
237+
{
238+
$this->validator->validate(
239+
'foo@bar.fr@',
240+
new Email(array(
241+
'message' => 'myMessage',
242+
$checkType => true,
243+
))
244+
);
245+
246+
$this
247+
->buildViolation('myMessage')
248+
->setParameter('{{ value }}', '"foo@bar.fr@"')
249+
->setCode($violation)
250+
->assertRaised();
251+
}
252+
253+
public function provideCheckTypes()
254+
{
255+
return array(
256+
array('checkMX', Email::MX_CHECK_FAILED_ERROR),
257+
array('checkHost', Email::HOST_CHECK_FAILED_ERROR),
258+
);
259+
}
232260
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function getInvalidUrls()
167167
array('http://example.com/exploit.html?<script>alert(1);</script>'),
168168
array('http://example.com/exploit.html?hel lo'),
169169
array('http://example.com/exploit.html?not_a%hex'),
170+
array('http://'),
170171
);
171172
}
172173

0 commit comments

Comments
 (0)
0