Skip to content

Commit bcb1b2d

Browse files
minor #18199 [Validator] Test DNS Url constraints using checkdnsrr() mock (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Validator] Test DNS Url constraints using checkdnsrr() mock | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- a4b42d1 [Validator] Test DNS Url constraints using checkdnsrr() mock
2 parents c7686a3 + a4b42d1 commit bcb1b2d

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy