Skip to content

Commit 8d3a492

Browse files
committed
minor #12048 [PhpUnitBridge] Updated the DnsMock example (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #12048). Discussion ---------- [PhpUnitBridge] Updated the DnsMock example Fixes #11902. Commits ------- 7c8a578 [PhpUnitBridge] Updated the DnsMock example
2 parents a37c878 + 7c8a578 commit 8d3a492

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

components/phpunit_bridge.rst

Lines changed: 14 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,23 @@ 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;
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('[email protected]', $constraint);
567+
$validator = new DomainValidator(['checkDnsRecord' => true]);
568+
$isValid = $validator->validate('example.com');
569569

570570
// ...
571571
}

0 commit comments

Comments
 (0)