@@ -527,20 +527,19 @@ functions:
527
527
Use Case
528
528
~~~~~~~~
529
529
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::
532
533
534
+ use App\Validator\DomainValidator;
533
535
use PHPUnit\Framework\TestCase;
534
- use Symfony\Component\Validator\Constraints\Email;
535
536
536
537
class MyTest extends TestCase
537
538
{
538
539
public function testEmail()
539
540
{
540
- $validator = ...
541
- $constraint = new Email(['checkMX' => true]);
542
-
543
- $result = $validator->validate('[email protected] ', $constraint);
541
+ $validator = new DomainValidator(['checkDnsRecord' => true]);
542
+ $isValid = $validator->validate('example.com');
544
543
545
544
// ...
546
545
}
@@ -550,22 +549,22 @@ In order to avoid making a real network connection, add the ``@dns-sensitive``
550
549
annotation to the class and use the ``DnsMock::withMockedHosts() `` to configure
551
550
the data you expect to get for the given hosts::
552
551
552
+ use App\Validator\DomainValidator;
553
553
use PHPUnit\Framework\TestCase;
554
- use Symfony\Component\Validator\Constraints\Email;
555
554
556
555
/**
557
556
* @group dns-sensitive
558
557
*/
559
- class MyTest extends TestCase
558
+ class DomainValidatorTest extends TestCase
560
559
{
561
560
public function testEmails()
562
561
{
563
- DnsMock::withMockedHosts(['example.com' => [['type' => 'MX']]]);
564
-
565
- $validator = ...
566
- $constraint = new Email(['checkMX' => true]);
562
+ DnsMock::withMockedHosts([
563
+ 'example.com' => [['type' => 'A', 'ip' => '1.2.3.4']],
564
+ ]);
567
565
568
- $result = $validator->validate('[email protected] ', $constraint);
566
+ $validator = new DomainValidator(['checkDnsRecord' => true]);
567
+ $isValid = $validator->validate('example.com');
569
568
570
569
// ...
571
570
}
0 commit comments