[Validator] Test DNS Email constraints using checkdnsrr() mock

This commit is contained in:
Nicolas Grekas 2016-03-15 18:45:16 +01:00
parent 4fece28773
commit 165755a01f
4 changed files with 43 additions and 4 deletions

View File

@ -11,7 +11,7 @@
*/
// Please update when phpunit needs to be reinstalled with fresh deps:
// Cache-Id-Version: 2015-11-28 09:05 UTC
// Cache-Id-Version: 2016-03-16 15:36 UTC
use Symfony\Component\Process\ProcessUtils;
@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
$zip->close();
chdir("phpunit-$PHPUNIT_VERSION");
passthru("$COMPOSER remove --no-update symfony/yaml");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\"");
passthru("$COMPOSER install --prefer-dist --no-progress --ansi");
file_put_contents('phpunit', <<<EOPHP
<?php

View File

@ -50,7 +50,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>

View File

@ -30,7 +30,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>

View File

@ -11,9 +11,13 @@
namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Bridge\PhpUnit\DnsMock;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\EmailValidator;
/**
* @group dns-sensitive
*/
class EmailValidatorTest extends AbstractConstraintValidatorTest
{
protected function createValidator()
@ -86,4 +90,39 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
array('example@localhost'),
);
}
/**
* @dataProvider getDnsChecks
*/
public function testDnsChecks($type, $violation)
{
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? false : $type))));
$constraint = new Email(array(
'message' => 'myMessage',
'MX' === $type ? 'checkMX' : 'checkHost' => true,
));
$this->validator->validate('foo@example.com', $constraint);
if (!$violation) {
$this->assertNoViolation();
} else {
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"foo@example.com"')
->assertRaised();
}
}
public function getDnsChecks()
{
return array(
array('MX', false),
array('MX', true),
array('A', false),
array('A', true),
array('AAAA', false),
array('AAAA', true),
);
}
}