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

This commit is contained in:
Nicolas Grekas 2016-03-16 15:58:21 +01:00
parent c7686a3624
commit a4b42d1fbd
1 changed files with 32 additions and 0 deletions

View File

@ -11,10 +11,14 @@
namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Bridge\PhpUnit\DnsMock;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Component\Validator\Constraints\UrlValidator;
use Symfony\Component\Validator\Validation;
/**
* @group dns-sensitive
*/
class UrlValidatorTest extends AbstractConstraintValidatorTest
{
protected function getApiVersion()
@ -187,6 +191,34 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest
array('git://[::1]/'),
);
}
/**
* @dataProvider getCheckDns
*/
public function testCheckDns($violation)
{
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? '' : 'A'))));
$constraint = new Url(array(
'checkDNS' => true,
'dnsMessage' => 'myMessage',
));
$this->validator->validate('http://example.com', $constraint);
if (!$violation) {
$this->assertNoViolation();
} else {
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"example.com"')
->assertRaised();
}
}
public function getCheckDns()
{
return array(array(true), array(false));
}
}
class EmailProvider