diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index ab22876a1f..fab7cf1867 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -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