Skip to content

Commit 208e7e6

Browse files
committed
[PhpUnitBridge] Updated the DnsMock example
1 parent 3a3f0b8 commit 208e7e6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

components/phpunit_bridge.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,20 +527,19 @@ functions:
527527
Use 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('[email protected]', $constraint);
541+
$validator = new DomainValidator(['checkDnsRecord' => true]);
542+
$isValid = $validator->validate('example.com');
544543

545544
// ...
546545
}
@@ -550,22 +549,22 @@ In order to avoid making a real network connection, add the ``@dns-sensitive``
550549
annotation to the class and use the ``DnsMock::withMockedHosts()`` to configure
551550
the 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;
555554

556555
/**
557556
* @group dns-sensitive
558557
*/
559-
class MyTest extends TestCase
558+
class DomainValidatorTest extends TestCase
560559
{
561560
public function testEmails()
562561
{
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+
]);
567565

568-
$result = $validator->validate('[email protected]', $constraint);
566+
$validator = new DomainValidator(['checkDnsRecord' => true]);
567+
$isValid = $validator->validate('example.com');
569568

570569
// ...
571570
}

0 commit comments

Comments
 (0)