[Validator] Test DNS Email constraints using checkdnsrr() mock
This commit is contained in:
parent
4fece28773
commit
165755a01f
4
phpunit
4
phpunit
@ -11,7 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Please update when phpunit needs to be reinstalled with fresh deps:
|
// 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;
|
use Symfony\Component\Process\ProcessUtils;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
|
|||||||
$zip->close();
|
$zip->close();
|
||||||
chdir("phpunit-$PHPUNIT_VERSION");
|
chdir("phpunit-$PHPUNIT_VERSION");
|
||||||
passthru("$COMPOSER remove --no-update symfony/yaml");
|
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");
|
passthru("$COMPOSER install --prefer-dist --no-progress --ansi");
|
||||||
file_put_contents('phpunit', <<<EOPHP
|
file_put_contents('phpunit', <<<EOPHP
|
||||||
<?php
|
<?php
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
||||||
<arguments>
|
<arguments>
|
||||||
<array>
|
<array>
|
||||||
<element><string>Symfony\Component\HttpFoundation</string></element>
|
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
|
||||||
</array>
|
</array>
|
||||||
</arguments>
|
</arguments>
|
||||||
</listener>
|
</listener>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
||||||
<arguments>
|
<arguments>
|
||||||
<array>
|
<array>
|
||||||
<element><string>Symfony\Component\HttpFoundation</string></element>
|
<element key="time-sensitive"><string>Symfony\Component\HttpFoundation</string></element>
|
||||||
</array>
|
</array>
|
||||||
</arguments>
|
</arguments>
|
||||||
</listener>
|
</listener>
|
||||||
|
@ -11,9 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Bridge\PhpUnit\DnsMock;
|
||||||
use Symfony\Component\Validator\Constraints\Email;
|
use Symfony\Component\Validator\Constraints\Email;
|
||||||
use Symfony\Component\Validator\Constraints\EmailValidator;
|
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group dns-sensitive
|
||||||
|
*/
|
||||||
class EmailValidatorTest extends AbstractConstraintValidatorTest
|
class EmailValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected function createValidator()
|
protected function createValidator()
|
||||||
@ -86,4 +90,39 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('example@localhost'),
|
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),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user