Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4b42d1

Browse files
[Validator] Test DNS Url constraints using checkdnsrr() mock
1 parent c7686a3 commit a4b42d1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Bridge\PhpUnit\DnsMock;
1415
use Symfony\Component\Validator\Constraints\Url;
1516
use Symfony\Component\Validator\Constraints\UrlValidator;
1617
use Symfony\Component\Validator\Validation;
1718

19+
/**
20+
* @group dns-sensitive
21+
*/
1822
class UrlValidatorTest extends AbstractConstraintValidatorTest
1923
{
2024
protected function getApiVersion()
@@ -187,6 +191,34 @@ public function getValidCustomUrls()
187191
array('git://[::1]/'),
188192
);
189193
}
194+
195+
/**
196+
* @dataProvider getCheckDns
197+
*/
198+
public function testCheckDns($violation)
199+
{
200+
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? '' : 'A'))));
201+
202+
$constraint = new Url(array(
203+
'checkDNS' => true,
204+
'dnsMessage' => 'myMessage',
205+
));
206+
207+
$this->validator->validate('http://example.com', $constraint);
208+
209+
if (!$violation) {
210+
$this->assertNoViolation();
211+
} else {
212+
$this->buildViolation('myMessage')
213+
->setParameter('{{ value }}', '"example.com"')
214+
->assertRaised();
215+
}
216+
}
217+
218+
public function getCheckDns()
219+
{
220+
return array(array(true), array(false));
221+
}
190222
}
191223

192224
class EmailProvider

0 commit comments

Comments
 (0)