@@ -527,20 +527,19 @@ functions:
527527Use Case
528528~~~~~~~~
529529
530- Consider the following example that uses the ``checkMX `` option of the ``Email ``
531- constraint to test the validity of the email domain::
530+ Consider the following example that tests a custom class called ``DomainValidator ``
531+ which defines a ``checkDnsRecord `` option to also validate that a domain is
532+ associated to a valid host::
532533
534+ use App\Validator\DomainValidator;
533535 use PHPUnit\Framework\TestCase;
534- use Symfony\Component\Validator\Constraints\Email;
535536
536537 class MyTest extends TestCase
537538 {
538539 public function testEmail()
539540 {
540- $validator = ...
541- $constraint = new Email(['checkMX' => true]);
542-
543- $result = $validator->validate('foo@example.com', $constraint);
541+ $validator = new DomainValidator(['checkDnsRecord' => true]);
542+ $isValid = $validator->validate('example.com');
544543
545544 // ...
546545 }
@@ -550,22 +549,23 @@ In order to avoid making a real network connection, add the ``@dns-sensitive``
550549annotation to the class and use the ``DnsMock::withMockedHosts() `` to configure
551550the data you expect to get for the given hosts::
552551
552+ use App\Validator\DomainValidator;
553553 use PHPUnit\Framework\TestCase;
554- use Symfony\Component\Validator\Constraints\Email ;
554+ use Symfony\Bridge\PhpUnit\DnsMock ;
555555
556556 /**
557557 * @group dns-sensitive
558558 */
559- class MyTest extends TestCase
559+ class DomainValidatorTest extends TestCase
560560 {
561561 public function testEmails()
562562 {
563- DnsMock::withMockedHosts(['example.com' => [['type' => 'MX']]]);
564-
565- $validator = ...
566- $constraint = new Email(['checkMX' => true]);
563+ DnsMock::withMockedHosts([
564+ 'example.com' => [['type' => 'A', 'ip' => '1.2.3.4']],
565+ ]);
567566
568- $result = $validator->validate('foo@example.com', $constraint);
567+ $validator = new DomainValidator(['checkDnsRecord' => true]);
568+ $isValid = $validator->validate('example.com');
569569
570570 // ...
571571 }
0 commit comments