Skip to content

Commit 32f264f

Browse files
Merge branch '2.8' into 3.2
* 2.8: 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 f53e81d + 8d0cfa4 commit 32f264f

File tree

10 files changed

+101
-14
lines changed

10 files changed

+101
-14
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,28 @@ private function getReflectionClass($id, Definition $definition)
325325

326326
$class = $this->container->getParameterBag()->resolveValue($class);
327327

328+
if ($deprecated = $definition->isDeprecated()) {
329+
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
330+
return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line);
331+
});
332+
}
333+
334+
$e = null;
335+
328336
try {
329337
$reflector = new \ReflectionClass($class);
330-
} catch (\ReflectionException $e) {
338+
} catch (\Exception $e) {
339+
} catch (\Throwable $e) {
340+
}
341+
342+
if ($deprecated) {
343+
restore_error_handler();
344+
}
345+
346+
if (null !== $e) {
347+
if (!$e instanceof \ReflectionException) {
348+
throw $e;
349+
}
331350
$reflector = false;
332351
}
333352

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
@@ -140,8 +140,8 @@
140140
</xsd:complexType>
141141

142142
<xsd:complexType name="property" mixed="true">
143-
<xsd:choice minOccurs="0" maxOccurs="1">
144-
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
143+
<xsd:choice minOccurs="0">
144+
<xsd:element name="property" type="property" maxOccurs="unbounded" />
145145
<xsd:element name="service" type="service" />
146146
</xsd:choice>
147147
<xsd:attribute name="type" type="argument_type" />
@@ -153,8 +153,8 @@
153153
</xsd:complexType>
154154

155155
<xsd:complexType name="argument" mixed="true">
156-
<xsd:choice maxOccurs="unbounded">
157-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
156+
<xsd:choice minOccurs="0">
157+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
158158
<xsd:element name="service" type="service" />
159159
</xsd:choice>
160160
<xsd:attribute name="type" type="argument_type" />
@@ -165,10 +165,9 @@
165165
<xsd:attribute name="strict" type="boolean" />
166166
</xsd:complexType>
167167

168-
<xsd:complexType name="call" mixed="true">
169-
<xsd:choice maxOccurs="unbounded">
170-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
171-
<xsd:element name="service" type="service" />
168+
<xsd:complexType name="call">
169+
<xsd:choice minOccurs="0">
170+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
172171
</xsd:choice>
173172
<xsd:attribute name="method" type="xsd:string" />
174173
</xsd:complexType>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,17 @@ public function testIgnoreServiceWithClassNotExisting()
493493
$this->assertTrue($container->hasDefinition('bar'));
494494
}
495495

496+
public function testProcessDoesNotTriggerDeprecations()
497+
{
498+
$container = new ContainerBuilder();
499+
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
500+
$container->register('foo', __NAMESPACE__.'\Foo');
501+
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
502+
503+
$pass = new AutowirePass();
504+
$pass->process($container);
505+
}
506+
496507
public function testEmptyStringIsKept()
497508
{
498509
$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 <[email protected]>
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+
240+
new Email(array(
241+
'message' => 'myMessage',
242+
$checkType => true,
243+
))
244+
);
245+
246+
$this
247+
->buildViolation('myMessage')
248+
->setParameter('{{ value }}', '"[email protected]@"')
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)