mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-12 11:06:31 +00:00
removed code related to the Symfony Validator Component as it is going to be integrated in Symfony instead
This commit is contained in:
+1
-2
@@ -10,8 +10,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">= 5.3.3",
|
||||
"doctrine/common": "~2.2",
|
||||
"symfony/validator": "dev-master"
|
||||
"doctrine/common": "~2.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
|
||||
class EmailExtra extends Email
|
||||
{
|
||||
public $strict = false;
|
||||
public $verbose = false;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
/**
|
||||
* EmailExtraValidator
|
||||
*
|
||||
* @author Eduardo Gulias Davis <me@egulias.com>
|
||||
*/
|
||||
class EmailExtraValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (null === $value || '' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||
throw new UnexpectedTypeException($value, 'string');
|
||||
}
|
||||
|
||||
$validator = new EmailValidator();
|
||||
$valid = $validator->isValid($value, $constraint->checkMX, $constraint->strict);
|
||||
|
||||
if ($constraint->verbose) {
|
||||
$constraint->message .= implode(',', $this->getWarnings());
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
if ($constraint->verbose) {
|
||||
$constraint->message .= "Error code: {$validator->getError()}";
|
||||
}
|
||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\Tests\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Egulias\Constraints\EmailExtra;
|
||||
use Egulias\Constraints\EmailExtraValidator;
|
||||
|
||||
class EmailExtraValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new EmailExtraValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
}
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate(null, new EmailExtra());
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new EmailExtra());
|
||||
}
|
||||
|
||||
/**
|
||||
* * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||
* */
|
||||
public function testExpectsStringCompatibleType()
|
||||
{
|
||||
$this->validator->validate(new \stdClass(), new EmailExtra());
|
||||
}
|
||||
|
||||
/**
|
||||
* * @dataProvider getValidEmails
|
||||
* */
|
||||
public function testValidEmails($email)
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate($email, new EmailExtra());
|
||||
}
|
||||
|
||||
public function getValidEmails()
|
||||
{
|
||||
return array(
|
||||
array('fabien@symfony.com'),
|
||||
array('example@example.co.uk'),
|
||||
array('fabien_potencier@example.fr'),
|
||||
array('example@localhost'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* * @dataProvider getInvalidEmails
|
||||
* */
|
||||
public function testInvalidEmails($email)
|
||||
{
|
||||
$constraint = new EmailExtra(
|
||||
array(
|
||||
'message' => 'myMessage'
|
||||
)
|
||||
);
|
||||
|
||||
$this->context->expects($this->once())->method('addViolation')
|
||||
->with(
|
||||
'myMessage',
|
||||
array('{{ value }}' => $email,)
|
||||
);
|
||||
|
||||
$this->validator->validate($email, $constraint);
|
||||
}
|
||||
|
||||
public function getInvalidEmails()
|
||||
{
|
||||
return array(
|
||||
array('example'),
|
||||
array('example@'),
|
||||
array('example@example.com@example.com'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user