8000 [Validator] Test DNS Email constraints using checkdnsrr() mock · dunglas/symfony@165755a · GitHub
[go: up one dir, main page]

Skip to content

Commit 165755a

Browse files
[Validator] Test DNS Email constraints using checkdnsrr() mock
1 parent 4fece28 commit 165755a

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

phpunit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// Please update when phpunit needs to be reinstalled with fresh deps:
14-
// Cache-Id-Version: 2015-11-28 09:05 UTC
14+
// Cache-Id-Version: 2016-03-16 15:36 UTC
1515

1616
use Symfony\Component\Process\ProcessUtils;
1717

@@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
5252
$zip->close();
5353
chdir("phpunit-$PHPUNIT_VERSION");
5454
passthru("$COMPOSER remove --no-update symfony/yaml");
55-
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
55+
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\"");
5656
passthru("$COMPOSER install --prefer-dist --no-progress --ansi");
5757
file_put_contents('phpunit', <<<EOPHP
5858
<?php

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
5151
<arguments>
5252
<array>
53-
<element><string>Symfony\Component\HttpFoundation</string></element>
53+
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
5454
</array>
5555
</arguments>
5656
</listener>

src/Symfony/Component/HttpKernel/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
3131
<arguments>
3232
<array>
33-
<element><string>Symfony\Component\HttpFoundation</string></element>
33+
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
3434
</array>
3535
</arguments>
3636
</listener>

src/Symfony/Component/Validator/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('foo@example.com', $constraint);
107+
108+
if (!$violation) {
109+
$this->assertNoViolation();
110+
} else {
111+
$this->buildViolation('myMessage')
112+
->setParameter('{{ value }}', '"foo@example.com"')
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)
0