[Validator] Test DNS Url constraints using checkdnsrr() mock
This commit is contained in:
parent
c7686a3624
commit
a4b42d1fbd
@ -11,10 +11,14 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Bridge\PhpUnit\DnsMock;
|
||||||
use Symfony\Component\Validator\Constraints\Url;
|
use Symfony\Component\Validator\Constraints\Url;
|
||||||
use Symfony\Component\Validator\Constraints\UrlValidator;
|
use Symfony\Component\Validator\Constraints\UrlValidator;
|
||||||
use Symfony\Component\Validator\Validation;
|
use Symfony\Component\Validator\Validation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group dns-sensitive
|
||||||
|
*/
|
||||||
class UrlValidatorTest extends AbstractConstraintValidatorTest
|
class UrlValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected function getApiVersion()
|
protected function getApiVersion()
|
||||||
@ -187,6 +191,34 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('git://[::1]/'),
|
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
|
class EmailProvider
|
||||||
|
Reference in New Issue
Block a user