Skip to content

Commit 9ee8d37

Browse files
[Validator] Test DNS Email constraints using checkdnsrr() mock
1 parent 3682e81 commit 9ee8d37

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Tests/Constraints/EmailValidatorTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
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

18+
/**
19+
* @group dns-sensitive
20+
*/
1721
class EmailValidatorTest extends AbstractConstraintValidatorTest
1822
{
1923
protected function createValidator()
@@ -86,4 +90,39 @@ public function getInvalidEmails()
8690
array('example@localhost'),
8791
);
8892
}
93+
94+
/**
95+
* @dataProvider getDnsChecks
96+
*/
97+
public function testDnsChecks($type, $violation)
98+
{
99+
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? false : $type))));
100+
101+
$constraint = new Email(array(
102+
'message' => 'myMessage',
103+
'MX' === $type ? 'checkMX' : 'checkHost' => true,
104+
));
105+
106+
$this->validator->validate('[email protected]', $constraint);
107+
108+
if (!$violation) {
109+
$this->assertNoViolation();
110+
} else {
111+
$this->buildViolation('myMessage')
112+
->setParameter('{{ value }}', '"[email protected]"')
113+
->assertRaised();
114+
}
115+
}
116+
117+
public function getDnsChecks()
118+
{
119+
return array(
120+
array('MX', false),
121+
array('MX', true),
122+
array('A', false),
123+
array('A', true),
124+
array('AAAA', false),
125+
array('AAAA', true),
126+
);
127+
}
89128
}

0 commit comments

Comments
 (0)