Skip to content

Commit

Permalink
minor #18196 [Validator] Test DNS Email constraints using checkdnsrr(…
Browse files Browse the repository at this point in the history
…) mock (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[Validator] Test DNS Email constraints using checkdnsrr() mock

| Q             | A
| ------------- | ---
| Branch        | 2.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

165755a [Validator] Test DNS Email constraints using checkdnsrr() mock
  • Loading branch information
nicolas-grekas committed Mar 16, 2016
2 parents 54f4f88 + 165755a commit 092a42b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions phpunit
Expand Up @@ -11,7 +11,7 @@
*/

// Please update when phpunit needs to be reinstalled with fresh deps:
// Cache-Id-Version: 2015-11-28 09:05 UTC
// Cache-Id-Version: 2016-03-16 15:36 UTC

use Symfony\Component\Process\ProcessUtils;

Expand Down Expand Up @@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
$zip->close();
chdir("phpunit-$PHPUNIT_VERSION");
passthru("$COMPOSER remove --no-update symfony/yaml");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\"");
passthru("$COMPOSER install --prefer-dist --no-progress --ansi");
file_put_contents('phpunit', <<<EOPHP
<?php
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -50,7 +50,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/phpunit.xml.dist
Expand Up @@ -30,7 +30,7 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
Expand Down
Expand Up @@ -11,9 +11,13 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Bridge\PhpUnit\DnsMock;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\EmailValidator;

/**
* @group dns-sensitive
*/
class EmailValidatorTest extends AbstractConstraintValidatorTest
{
protected function createValidator()
Expand Down Expand Up @@ -86,4 +90,39 @@ public function getInvalidEmails()
array('example@localhost'),
);
}

/**
* @dataProvider getDnsChecks
*/
public function testDnsChecks($type, $violation)
{
DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? false : $type))));

$constraint = new Email(array(
'message' => 'myMessage',
'MX' === $type ? 'checkMX' : 'checkHost' => true,
));

$this->validator->validate('foo@example.com', $constraint);

if (!$violation) {
$this->assertNoViolation();
} else {
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"foo@example.com"')
->assertRaised();
}
}

public function getDnsChecks()
{
return array(
array('MX', false),
array('MX', true),
array('A', false),
array('A', true),
array('AAAA', false),
array('AAAA', true),
);
}
}

0 comments on commit 092a42b

Please sign in to comment.