Skip to content

Commit 5794c2c

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 #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 c1e6871 + 9ee8d37 commit 5794c2c

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

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

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('[email protected]', $constraint);
124+
125+
if (!$violation) {
126+
$this->assertNoViolation();
127+
} else {
128+
$this->buildViolation('myMessage')
129+
->setParameter('{{ value }}', '"[email protected]"')
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)